Subject: Re: sequential numbering in xslt
From: a kusa <akusa8@xxxxxxxxx>
Date: Mon, 11 Jan 2010 14:28:51 -0600
|
I worked with the solution that Jim was kind enough to lay out
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:saxon="http://saxon.sf.net/" extension-element-prefixes="saxon">
<xsl:param name="previous-number" select="1" />
<xsl:template match="/">
<xsl:call-template name="example">
<xsl:with-param name="documents"
select="collection('file:///L:/input/?select=*.xml')" />
<xsl:with-param name="previous-number" select="$previous-number" />
</xsl:call-template>
</xsl:template>
<xsl:template name="example">
<xsl:param name="documents">
<xsl:param name="previous-number" required="yes" />
<xsl:if test="$documents[1]">
<xsl:variable name="current-number" as="xs:integer"
select="xs:integer($previous-number+1)" />
<car seq="{$current-number}">
<xsl:copy-of select="@*|node()"/>
</car>
<xsl:call-template name="example">
<xsl:with-param name="documents" select="remove($documents, 1)" />
<xsl:with-param name="previous-number" select="$current-number" />
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
And my L:/input contains 2 XML files for now. The root element of both is
<car>
On Mon, Jan 11, 2010 at 2:21 PM, David Carlisle <davidc@xxxxxxxxx> wrote:
>
>
>> When I say $document[1], it considers all files as $documents[1].
>
> This is not possible. There is no data value in xpath that corresponds to
> multiple documents except a sequence of document nodes, and as you can
> not nest sequences, it is not possible to return a sequence of more than
> one item as a result of $documents[1].
>
> What expression did you actually use to give the impression that
> $document[1] is all files.
>
> David
|