Copied to clipboard

Flag this post as spam?

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


  • John Halsey 59 posts 220 karma points
    Feb 24, 2014 @ 15:27
    John Halsey
    0

    How to access the second root node in tree with XSLT

    I have written a small XSLT script to list out banner images. (see code below).

    I have 2 root nodes, one called home, and one called banner.  Our designers want a rolling banner on every page, so figured I would stick the macro in the main template, but also to make it easier, I have put the banner folder, with all the images as a second root node, see image.

    My question is, how to I target just that node in my xslt code?

    <ul>
    <xsl:for-each select="Banner/BannerImage [@isDoc]">
    <xsl:choose>
    <xsl:when test="url != ''">
                    <!-- check to see if the new browser check box was ticked -->
    <xsl:variable name="window">
    <xsl:choose>
    <xsl:when test="linkTarget = 1">
       _blank
    </xsl:when>
    <xsl:otherwise>
       _self
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>
                    <!-- did they provide an alt text, if not, use the value in the image name -->
    <xsl:variable name="alt">
    <xsl:choose>
                            <xsl:when test="altText != ''">
                                <xsl:value-of select="altText"/>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:value-of select="Name"/>
                            </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>
    <xsl:variable name="mediaImage" select="umbraco.library:GetMedia(bannerImage, false())" />
                    <li>
                        <a href="{url}" target="$window">
    <img src="{$mediaImage/umbracoFile}" alt="{$alt}" />
                        </a>
                    </li>
    </xsl:when>
                <xsl:otherwise>
    <xsl:variable name="alt">
    <xsl:choose>
                            <xsl:when test="altText != ''">
                                <xsl:value-of select="altText"/>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:value-of select="Name"/>
                            </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>
    <xsl:variable name="mediaImage" select="umbraco.library:GetMedia(bannerImage, false())" />
                    <li>
    <img src="{$mediaImage/umbracoFile}" alt="{$alt}" />
                    </li>
                </xsl:otherwise>
    </xsl:choose>

    </xsl:for-each>

    </ul>

    FYI, the Banner folder has and alias Banner, and each Image node has an alias BannerImage.

    Thank you for any advice.

  • John Halsey 59 posts 220 karma points
    Feb 24, 2014 @ 15:29
    John Halsey
    0

    Should also mention, when I run this, nothing happens.  It renders blank space, so obviously isn't finding the BannerImages.

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Feb 24, 2014 @ 15:35
    Dennis Aaen
    0

    Hi John,

    You can use the GetXmlNodeById library method to get the XML from at specific node. You can find the documentation here: http://our.umbraco.org/wiki/reference/umbracolibrary/getxmlnodebyid

    <xsl:value-of select="umbraco.library:GetXmlNodeById(1234)"/>
    <xsl:for-each select="umbraco.library:GetXmlNodeById(1234)/BannerImage[@isDoc]">

    Hope this helps,

    /Dennis

  • John Halsey 59 posts 220 karma points
    Feb 24, 2014 @ 15:54
    John Halsey
    0

    Beautiful. This worked a treat.  

  • 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