Copied to clipboard

Flag this post as spam?

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


  • Graham Mulcock 26 posts 48 karma points
    May 20, 2010 @ 12:08
    Graham Mulcock
    0

    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 "&#x00A0;"> ]>
    <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']) &gt; 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']) &gt; 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....?

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    May 20, 2010 @ 12:33
    Lee Kelleher
    0

    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.

  • Graham Mulcock 26 posts 48 karma points
    May 20, 2010 @ 12:53
    Graham Mulcock
    1

    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)"/>

Please Sign in or register to post replies

Write your reply to:

Draft