Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Showing multiple nested tags 1

Status
Not open for further replies.

silverfang

Programmer
Aug 30, 2005
3
BE
When I am working with an xsl stylesheet and I want to display something like:
<1>
<2>
<3>
<4></4>
<4></4>
<4></4>
<4></4>
</3>
</2>
<2>
<3>
<4></4>
<4></4>
</3>
</2>
</1>

... with <xsl:value-of select="1/2/3/4"/> it only displays the first <4>-tag of each <3>-element. How can I display them al if I have a random number of <4>-tags
 
There's 2 main ways of doing it. You can use a for-each:
Code:
<xsl:for-each select="1/2/3/4">
  <xsl:value-of select="."/>
</xsl:for-each>
Or, my preferred option, you can use templates. Templates give more meaning to the code and make it more readable:
Code:
<xsl:template match="/">
  <xsl:apply-templates select="1/2/3/4"/>
</xsl:template>
<xsl:template match="4">
  <xsl:value-of select="."/>
</xsl:template>
I would stick to templates where possible, but sometimes it makes more sense to use for-each.

Jon

"I don't regret this, but I both rue and lament it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top