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.
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>
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
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?
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:
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:
/Chriztian
is working on a reply...