Copied to clipboard

Flag this post as spam?

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


  • Bon Searle 6 posts 26 karma points
    Oct 11, 2013 @ 17:38
    Bon Searle
    0

    Selecting from siblings of site root?

    Hi, i'm really ew to XLST and have spent the last few hours trying to work out how to select the children of a neighbouring node and display their names using a foreach.

    The page "our work" should pull a list of client names from the clients node where each client is stored as a separate node.

    I looked at how the umedia slider example works as thats a similar kind of setup but the XLST they use $currentPage/parent::*/child::*[@level=1] returns nothing when used on my node structure.

    All i'm trying to do is list each client name (@nodeName) one by one in <p> tags but its proving far harder than i estimated.

    Any help making sense of what i'm doing wrong would be brilliant.

    Cheers!

    Bon

  • Bon Searle 6 posts 26 karma points
    Oct 11, 2013 @ 17:46
    Bon Searle
    0

    OK i've got nearer with the following:

    <xsl:variable name="snode" select="$currentPage/../../*[@isDoc]" />

     <xsl:for-each select="$snode/child::*">

          <p>

     <xsl:value-of select="@nodeName"/>

          </p>

    But this shows the children of all nodes and not just tgose of the clients node?

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Oct 16, 2013 @ 08:38
    Chriztian Steinmeier
    0

    Hi Bon,

    To solve problems like this, you usually just need to do a couple of intermediate variables to make everything much more readable and easier to understand:

    <!-- Grab the Site node, wherever you are within the site -->
    <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />
    
    <!-- Find the Clients - (Use the DocumentType alias) -->
    <xsl:variable name="clientsRoot" select="$siteRoot/../Clients" />
    
    <!-- Process all children of the Clients node -->
    <xsl:for-each select="$clientsRoot/*[@isDoc]">
        <p><xsl:value-of select="@nodeName" /></p>
    </xsl:for-each>
    

    Note: You need to use the alias of the Clients node in step 2 - it's more specific to your solution, but the readability of the code goes way up. Same for the final step - if your client nodes are named Client you should do this instead:

    <!-- Process all children of the Client nodes -->
    <xsl:for-each select="$clientsRoot/Client">
        <p><xsl:value-of select="@nodeName" /></p>
    </xsl:for-each>
    

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft