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.
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?
FYI, the Banner folder has and alias Banner, and each Image node has an alias BannerImage.
Thank you for any advice.
Should also mention, when I run this, nothing happens. It renders blank space, so obviously isn't finding the BannerImages.
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
Beautiful. This worked a treat.
is working on a reply...