Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Back again... I'm having difficulty referencing a different node in my XSLT. I have a page that should display a list of news items, in which the list is generated from a number of files under a different parent node. For example, the hierarchy is:
root -> News -> NewsItem List -> NewsItems -> NewsItem#1 -> NewsItem#2 : :
Using this XSLT, nothing happens....
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxml="urn:schemas-microsoft-com:xslt" xmlns:umbraco.library="urn:umbraco.library" exclude-result-prefixes="msxml umbraco.library"><xsl:output encoding="utf-8" indent="yes" method="xml" omit-xml-declaration="yes" /><xsl:param name="currentPage"/><xsl:template match="/"> <xsl:variable name="parentNode" select="$currentPage/ancestor-or-self::node[@alias = 'Site_Newsletters']"/> <ul> <xsl:apply-templates select="$parentNode/node[string(data[@alias='umbracoNaviHide']) != '1']"> <xsl:sort select="@nodeName" data-type="text" order="descending" /> </xsl:apply-templates> </ul></xsl:template><xsl:template match="node"> <li> <a href="{umbraco.library:NiceUrl(@id)}"> <!-- check if the node has the 'linkText' set, otherwise fallback on the 'nodeName' --> <xsl:choose> <xsl:when test="string-length(data[@alias='linkText']) > 0"> <xsl:value-of select="data[@alias='linkText']" /> </xsl:when> <xsl:otherwise> <xsl:value-of select="@nodeName" /> </xsl:otherwise> </xsl:choose> </a> <!-- check if the node has any children (that are not hidden from nav) --> <xsl:if test="count(node[string(data[@alias='umbracoNaviHide']) != '1']) > 0"> <ul> <!-- apply the templates for the sub-child nodes --> <xsl:apply-templates select="node[string(data[@alias='umbracoNaviHide']) != '1']"> <xsl:sort select="@nodeName" data-type="text" order="ascending" /> </xsl:apply-templates> </ul> </xsl:if> </li></xsl:template></xsl:stylesheet>Any clues....?
Hi Graham,
My guess is that the value of 'parentNode' isn't quite correct. Try debugging it, see what you get back:
<xsl:variable name="parentNode" select="$currentPage/ancestor-or-self::node[@alias = 'Site_Newsletters']"/> <xmp> <xsl:copy-of select="$parentNode" /> </xmp>
If it's not the right node, then fix the XPath accordingly to get what you want - before passing it to the apply-templates.
Cheers, Lee.
Thanks, Lee. Managed to fix it (at least as a temporary measure) by referencing the node ID:
<xsl:variable name="parentNode" select="umbraco.library:GetXmlNodeById(1150)"/>
is working on a reply...
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.
Continue discussion
Accessing alternate node in XSLT
Back again... I'm having difficulty referencing a different node in my XSLT. I have a page that should display a list of news items, in which the list is generated from a number of files under a different parent node. For example, the hierarchy is:
root
-> News
-> NewsItem List
-> NewsItems
-> NewsItem#1
-> NewsItem#2
:
:
Using this XSLT, nothing happens....
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxml="urn:schemas-microsoft-com:xslt" xmlns:umbraco.library="urn:umbraco.library" exclude-result-prefixes="msxml umbraco.library">
<xsl:output encoding="utf-8" indent="yes" method="xml" omit-xml-declaration="yes" />
<xsl:param name="currentPage"/>
<xsl:template match="/">
<xsl:variable name="parentNode" select="$currentPage/ancestor-or-self::node[@alias = 'Site_Newsletters']"/>
<ul>
<xsl:apply-templates select="$parentNode/node[string(data[@alias='umbracoNaviHide']) != '1']">
<xsl:sort select="@nodeName" data-type="text" order="descending" />
</xsl:apply-templates>
</ul>
</xsl:template>
<xsl:template match="node">
<li>
<a href="{umbraco.library:NiceUrl(@id)}">
<!-- check if the node has the 'linkText' set, otherwise fallback on the 'nodeName' -->
<xsl:choose>
<xsl:when test="string-length(data[@alias='linkText']) > 0">
<xsl:value-of select="data[@alias='linkText']" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@nodeName" />
</xsl:otherwise>
</xsl:choose>
</a>
<!-- check if the node has any children (that are not hidden from nav) -->
<xsl:if test="count(node[string(data[@alias='umbracoNaviHide']) != '1']) > 0">
<ul>
<!-- apply the templates for the sub-child nodes -->
<xsl:apply-templates select="node[string(data[@alias='umbracoNaviHide']) != '1']">
<xsl:sort select="@nodeName" data-type="text" order="ascending" />
</xsl:apply-templates>
</ul>
</xsl:if>
</li>
</xsl:template>
</xsl:stylesheet>
Any clues....?
Hi Graham,
My guess is that the value of 'parentNode' isn't quite correct. Try debugging it, see what you get back:
If it's not the right node, then fix the XPath accordingly to get what you want - before passing it to the apply-templates.
Cheers, Lee.
Thanks, Lee. Managed to fix it (at least as a temporary measure) by referencing the node ID:
<xsl:variable name="parentNode" select="umbraco.library:GetXmlNodeById(1150)"/>
is working on a reply...
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.