Copied to clipboard

Flag this post as spam?

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


  • Elad Lachmi 112 posts 144 karma points
    Oct 23, 2011 @ 21:37
    Elad Lachmi
    0

    Get by document type only children of the current node

    Hi,

    I have an XSLT file which lists all pages of type "broker". Now I want to add a subtree with a copy of the site translated to Japanese. The problem is that now the XSLT is picking up both the nodes under the current page and the nodes under the translated copy of the current page. Here is the XSLT:

    <xsl:param name="currentPage"/>

    <xsl:template match="/">

    <!-- start writing XSLT -->
    <ul class="footer-broker-list">
    <xsl:for-each select="$currentPage/ancestor-or-self::*//broker [@isDoc]">
    <xsl:if test="string(umbracoNaviHide) != '1'">
    <li>
    <a>
    <xsl:attribute name="href">
    <xsl:value-of select="umbraco.library:NiceUrl(current()/@id)"/>
    </xsl:attribute>
    <xsl:attribute name="style">
    text-decoration: none;
    </xsl:attribute>
    <xsl:value-of select="./brokerName" /></a></li>
    </xsl:if>
    </xsl:for-each>
    </ul>
    </xsl:template>

     

    How can I modify this XSLT so it only looks at direct children of the current page?

    Thank you!

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Oct 23, 2011 @ 21:53
    Dennis Aaen
    0

    Hi Elad,

    I think you can do it with this xpath expression

    <xsl:for-each select="$currentPage/broker [@isDoc]">

    Hope it works for you.

    /Dennis

  • Elad Lachmi 112 posts 144 karma points
    Oct 23, 2011 @ 23:58
    Elad Lachmi
    0

    The problem is that the list is displayed on all the pages.

    This would work if I used the list macro only on the parent page.

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Oct 24, 2011 @ 00:18
    Dennis Aaen
    0

    Okay,

    I think you have to go up to the root in your tree and then list all the pages of the broker document type.

    Maybe, something like this, will solve your question.

    <xsl:for-each select="$currentPage/ancestor-or-self::broker [@isDoc]">

    Hopefully this will help you further.

    /Dennis



  • Dan Okkels Brendstrup 101 posts 197 karma points
    Nov 16, 2011 @ 16:15
    Dan Okkels Brendstrup
    0

    Hi Elad,

    Assuming both your English and your Japanese sites are sibling nodes of the doctype Frontpage, you could do this:

    <xsl:param name="currentPage"/>
    <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::Frontpage">
     
    <xsl:template match="/">
      <ul class="footer-broker-list">
        <xsl:apply-templates select="$siteRoot//Broker[umbracoNaviHide != 1 and normalize-space(brokerName)]"/>
      </ul>
    </xsl:template>
     
    <xsl:template match="Broker">
      <li>
        <a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:value-of select="brokerName"/>
        </a>
      </li>
    </xsl:template>
    Then you'll only get the Broker nodes under the current site (that are not hidden, and which have content for their brokerName property).
    For performance reasons, you should create as specific an XPath targeting as you can, e.g. $siteRoot/Brokers/Broker, or whatever your structure is.
Please Sign in or register to post replies

Write your reply to:

Draft