Copied to clipboard

Flag this post as spam?

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


  • Wasim 14 posts 34 karma points
    Feb 10, 2011 @ 19:48
    Wasim
    0

    How to get the doc type from Multi Node Tree picker

    Hello,

    I'm using the Multi Node Tree picker to get different types of content and display it on a page. These contents are boxes like Teasers, Quotes etc. I would like to loop through each node and check it's doc type. This will help me to style it appropriately. I have some sample code below but couldn't find a way to get the doc type so all the boxes look the same:


    <!-- First we check that the Multi-node Tree Picker has any nodeId values -->
      <xsl:if test="$currentPage/teasersList/MultiNodePicker/nodeId">
        
           
          <!-- Loop through each of the nodeId values -->
        <xsl:for-each select="$currentPage/teasersList/MultiNodePicker/nodeId">

            <!-- Since we only have the nodeId value, we need to get the actual content node using umbraco.library's GetXmlNodeById method -->
            <!-- If you prefer to use pure XPath, then used this: "$currentPage/ancestor-or-self::*[@isDoc and @level = 1]/descendant-or-self::*[@isDoc and @id = current()]" -->
            <xsl:variable name="node" select="umbraco.library:GetXmlNodeById(.)" />
            
            <div style="border:1px solid #000;width:200px; margin-bottom:10px;">
              <xsl:choose>
                <xsl:when test="$node/teaserHeader !=''">
                  <div><xsl:value-of select="$node/teaserHeader"/></div>
                  <xsl:if test="$node/teaserSummary !=''">
                    <div style="padding-top:10px;"><xsl:value-of select="$node/teaserSummary"/></div>
                  </xsl:if>
                </xsl:when>
                <xsl:otherwise>
                  <div><xsl:value-of select="$node/teaserSummary"/></div>
                </xsl:otherwise>
              </xsl:choose>
              <xsl:if test="$node/quoteText !=''">
                <blockquote><xsl:value-of select="$node/quoteText" disable-output-escaping="yes"/></blockquote>
              </xsl:if>
            </div>

          </xsl:for-each>


      </xsl:if>
    So basically while looping through each of the nodeId values I need to get the doc type of each node so that I can give it a different look. The doc types for my 2 boxes are Teaserbox and Quotebox



    Hope someone can help me out with some code sample.



    Thanks,

    Wasim
  • Wasim 14 posts 34 karma points
    Feb 10, 2011 @ 19:56
    Wasim
    0

    sorry for the post above not showing properly. This forum has an error when trying to edit a post.

  • Rich Green 2246 posts 4008 karma points
    Feb 10, 2011 @ 20:32
    Rich Green
    0

    Hey,

    This will get you the doc type

     <xsl:value-of select="local-name($node)"/>

    Hope it helps!

    Rich

  • Wasim 14 posts 34 karma points
    Feb 11, 2011 @ 18:51
    Wasim
    0

    Hi Rich,

    Thanks for the reply but I don't understand how to use that as i'm quite new to xslt. What is "local-name" or is that where I put the name of the doc type alias? So assuming my doctype is "Teaserbox" how do I create an if statement surrounding my styled div?

  • Wasim 14 posts 34 karma points
    Feb 11, 2011 @ 18:59
    Wasim
    0

    Hi again,

    Just tested. Got it:

    <xsl:if test="local-name($node) = 'Teaserbox'">
    <div>My custom box</div>
    </xsl:if>

    Thanks

  • 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