This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Absolute ordering -- determining order when position() won't work
- To: <xsl-list at mulberrytech dot com>
- Subject: Re: Absolute ordering -- determining order when position() won't work
- From: "Steve Muench" <Steve dot Muench at oracle dot com>
- Date: Mon, 4 Dec 2000 14:53:32 -0800
- References: <8E864C73E16B864BB594712EDB3C89A011A9DB@belmail2.datachannel.com>
- Reply-To: xsl-list at mulberrytech dot com
| I have XML which consists of elements which are either folders or files:
|
| <Folder name="foldera">
| <File name="a" />
| <Folder name="folderb">
| </ Folder>
| <File name="b" />
| <Folder name="folderc">
| <File name="c" />
| <File name="d" />
| </ Folder>
| </Folder>
|
| What I would like to do, is precede each file name with a number, like so:
| 1 a
| 2 b
| 3 c
| 4 d
Here's one possible solution:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>
<!-- When you match a Folder, apply templates for sub-Files and sub-Folders -->
<xsl:template match="Folder">
<xsl:apply-templates select="File|Folder"/>
</xsl:template>
<!-- When you match a File, print out an absolute number and its name -->
<xsl:template match="File">
<xsl:value-of select="count(preceding::File)+1"/>
<xsl:text> </xsl:text><xsl:value-of select="@name"/><xsl:text>
</xsl:text>
<xsl:apply-templates select="Folder"/>
</xsl:template>
</xsl:stylesheet>
______________________________________________________________
Steve Muench, Lead XML Evangelist & Consulting Product Manager
BC4J & XSQL Servlet Development Teams, Oracle Rep to XSL WG
Author "Building Oracle XML Applications", O'Reilly
http://www.oreilly.com/catalog/orxmlapp/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list