Re: Absolute ordering -- determining order when position() won't work

Subject: Re: Absolute ordering -- determining order when position() won't work
From: "Steve Muench" <Steve.Muench@xxxxxxxxxx>
Date: Mon, 4 Dec 2000 14:53:32 -0800
| 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>&#xa;</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


Current Thread