|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Absolute ordering -- determining order when position() w
| 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








