[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Re: [xsl] sequential numbering in xslt
Subject: Re: [xsl] sequential numbering in xslt From: a kusa <akusa8@xxxxxxxxx> Date: Mon, 4 Jan 2010 11:23:23 -0600 |
Hi Ken: Thanks for your response. I use saxon to read a directory of files, and using xsl:result-document, I output these xml files woth different names. I started with a random number and tried incrementing it but it obviously failed because of the xsl:variable limitations. Also, position() does not increment is that correct? Will it not be always 1? On Sun, Jan 3, 2010 at 2:48 PM, G. Ken Holman <gkholman@xxxxxxxxxxxxxxxxxxxx> wrote: > At 2010-01-03 14:41 -0600, a kusa wrote: >> >> I have a number of XML files as input, and I transform them into >> another XML format using XSLT. >> ... >> So, for example, if I had 5 input xml files a.xml, b.xml, c.xml, >> d.xml, e.xml, and I transformed them into Aout.xml, Bout.xml, >> Cout.xml, Dout.xml and Eout.xml , > > How are you accessing those 5 input files? > >> the output of which looks something >> like below: >> Output XML: >> >> <car seq="1"> >> <req>....<req> >> >> <body id="c1"> >> >> </body> >> >> </car> >> >> for every input file, in the transformation, I want to increment >> attribute 'seq' in the output file by 1 when I transform the input >> files using xslt. > > If you are accessing them in a for-each construct, then the position() > function gives you what you need: > >> I have tried <xsl:number> > > That is only for use in a single tree. > >> and tried writing a function. But the >> problem is that since variables in xslt are constants, there is no way >> to increment a number, store it in a temp variable and increment it >> for the next time in xslt 2.0 unlike procedural languages like C or >> C++. > > Correct, but you have blinders on thinking that is the way to approach the > problem. > >> Is there any other way of achieving this in XSLT 2.0? > > It depends on how you are accessing your 5 input files. > > The following would work if this is the way you are doing it: > > <xsl:for-each select="('a.xml','b.xml','c.xml','d.xml','e.xml')"> > <xsl:result-document href="{replace(.,'\.','out.')}"> > <car seq="{position()}"> > <xsl:apply-templates select="doc(.)"/> > ... > > Or something like: > > <xsl:for-each select="('a.xml','b.xml','c.xml','d.xml','e.xml')"> > <xsl:variable name="seq" select="position()"/> > <xsl:result-document href="{replace(.,'\.','out.')}"> > <xsl:for=each select="doc(.)"> > <car seq="{$seq}"> > ... > > (both untested, so please forgive any typos) > > I hope this helps. > > . . . . . . . . . . Ken > > -- > UBL and Code List training: Copenhagen, Denmark 2010-02-08/10 > XSLT/XQuery/XPath training after http://XMLPrague.cz 2010-03-15/19 > XSLT/XQuery/XPath training: San Carlos, California 2010-04-26/30 > Vote for your XML training: http://www.CraneSoftwrights.com/s/i/ > Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ > Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video > Video lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18 > Video overview: http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18 > G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx > Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc > Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] sequential numbering in x, G. Ken Holman | Thread | Re: [xsl] sequential numbering in x, David Carlisle |
Re: [xsl] reading a large XML file , David Carlisle | Date | Re: [xsl] Modern web site design wi, Eric J. Bowman |
Month |