Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 05, 2011 @ 11:37
    Fuji Kusaka
    0

    Checking Document Type

    Hi all,

    I have some issues while checking for a document type in my XSLT. What i need to do is check where am using a specific document type and if so i will will display the nodeName and all the child nodes from this documentType.

    My Structure is something like 

    Default

    Doc 1
    --- Sub Doc1
    --- Sub Doc 2
    --- Sub Doc 3 (documentType 'SuDoc')
    ---- Sub Sub Doc 1
    ---- Sub Sub Doc 2

     

     <xsl:if test="count(./*[@isDoc and string(umbracoNaviHide) !='1'])&gt;0">
          <xsl:choose>       
            <xsl:when test="@nodeTypeAlias='SuDoc'"> <!-- But this is the Old Schema -->
              <ul>
                    <xsl:value-of select="@nodeName"/> 
        </ul>
          </xsl:when>
                  <xsl:otherwise>
            
                <ul>
                 <xsl:for-each select="./* [@isDoc and string(umbracoNaviHide) !='1']">
                        <xsl:value-of select="@nodeName"/>   
                  </xsl:for-each> 
          </ul>
            
          </xsl:otherwise>
            
          </xsl:choose>
            </xsl:for-each>
         
        </xsl:if>

     

    Any suggestion ??

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Oct 05, 2011 @ 11:49
    Chriztian Steinmeier
    0

    Hi Fuji,

    Use the self:: axis to test the name of an element (or if it's in a variable, the name() function):

    <xsl:when test="self::SuDoc">
        <!-- do stuff -->
    </xsl:when>

    or:

    <xsl:when test="name() = $docTypeName">
        <!-- do stuff -->
    </xsl:when>

    Also - no need to count when testing for e.g. childnodes:

    <xsl:if test="*[@isDoc][not(umbracoNaviHide = 1)]">
        <!-- do stuff -->
    </xsl:if>

    /Chriztian

  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 05, 2011 @ 11:55
    Fuji Kusaka
    0

    OK let me give this a try. I did test self: but didnt work.

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Oct 05, 2011 @ 12:05
    Chriztian Steinmeier
    1

    OK - important to use two colons "::" for axes - just to be sure you got that. Otherwise you'll get an error about an undeclared "self" prefix.

    /Chriztian

  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 05, 2011 @ 12:09
    Fuji Kusaka
    0

    Yup it works i must have missed a colon. I even try the other one but this one is not working for me

    <xsl:whentest="name() = $docTypeName">
           
    <!-- do stuff -->
    </xsl:when>
  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 05, 2011 @ 15:30
    Fuji Kusaka
    0

    Chriztian,

    Can help out with this? here is my XSLT, it works fine but i need to get ride of extra

    • Tags "suCn". With the below code am getting 27 but only 6 should be displayed. This is a drop down menu navigation where the output should be something like

                      

    <xsl:if test="*[@isDoc][not(umbracoNaviHide = 1)]">
                  <ul style="border:1px solid #f00;">
                       <xsl:for-each select="./* [@isDoc and string(umbracoNaviHide) !='1']">
                               
                         <xsl:choose>
                                    <xsl:when test="self::
    SuDoc">
                                      
                                       <li class="disCn">
                                            <ul>
                                                    <xsl:call-template name="DisCn" />
                                              ul>
                                       li>
                                        
                                  xsl:when>
                           
                                <xsl:otherwise>
                                  
                                     <li class="suCn">                                        
                                             <xsl:call-template name="suCn" /> 
                                  li>
                                   
                                  
                              xsl:otherwise>
                      xsl:choose>
                         
                     
                  xsl:for-each>    
                    
                  ul>
                xsl:if>
                
                
            li>  
        xsl:for-each>
    ul>
    xsl:template>
        
     <xsl:template name="suCn">     
               <div class="suRs"><href="{umbraco.library:NiceUrl(@id)}"<xsl:value-of select="@nodeName" />a>div         
      xsl:template>
        
      
        <xsl:template name="DisCn">                           
                       <xsl:if test="*[@isDoc][not(umbracoNaviHide = 1)]">                 
                            <xsl:for-each select="./* [@isDoc and string(umbracoNaviHide) !='1']">
                               <li>                           
                                  <href="{umbraco.library:NiceUrl(@id)}" ><xsl:value-of select="@nodeName"/>a>                       
                              li>
                            xsl:for-each>                      
                        xsl:if>           
      xsl:template>
  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 05, 2011 @ 16:27
    Fuji Kusaka
    0

    Got it working here was my mistake 

    <xsl:if test="*[@isDoc][not(umbracoNaviHide = 1)]">
                  <ul style="border:1px solid #f00;">
      <li class="suCn">     <!-- Misplaced the Li Tag -->
                       <xsl:for-each select="./* [@isDoc and string(umbracoNaviHide) !='1']">
                               
                         <xsl:choose>
                                    <xsl:when test="self::
    SuDoc">
                                      <!-- Second Menu -->
                                       <li class="disCn">
                                            <ul>
                                                    <xsl:call-template name="DisCn" />
                                              </ul>
                                       </li>
                                       <!-- End of Second Menu --> 
                                  </xsl:when>
                           
                                <xsl:otherwise>
                                  <!-- First Menu -->
                                                                      
                                             <xsl:call-template name="suCn" /> 
                                  
                                   
                                  <!-- end of first menu -->
                              </xsl:otherwise>
                      </xsl:choose>
                         
                     
                  </xsl:for-each>    
                    
                  </ul>
                </xsl:if>
                
                
            </li>  
        </xsl:for-each>
    </li>
    </ul>
    </xsl:template>
        
     <xsl:template name="suCn">     
               <div class="suRs"><a href="{umbraco.library:NiceUrl(@id)}"> <xsl:value-of select="@nodeName" /></a></div>          
      </xsl:template>
        
      
        <xsl:template name="DisCn">                           
                       <xsl:if test="*[@isDoc][not(umbracoNaviHide = 1)]">                 
                            <xsl:for-each select="./* [@isDoc and string(umbracoNaviHide) !='1']">
                               <li>                           
                                  <a href="{umbraco.library:NiceUrl(@id)}" ><xsl:value-of select="@nodeName"/></a>                       
                              </li>
                            </xsl:for-each>                      
                        </xsl:if>           
      </xsl:template>
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies