[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: sequential numbering with for-each

Subject: Re: sequential numbering with for-each
From: "Heiko Niemann kontakt@xxxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 1 Sep 2016 21:33:33 -0000
Re:  sequential numbering with for-each
I just generated some sample data in variable foos. You would have to
replace it with some code that generates your desired list (a sequence of
strings as I understood your outline). My suggestion was not trying to
create the list and the numbering at the same time - but first create the
list (sequence) and iterate on that list to do the numbering.

So if you put 'for each /root/foo[@type = @ttype from 'root1']/foo1' and
whatever logic is needed to create your unnumbered list into variable foos
this should work - if I got your sample correctly.

Heiko



> Thanks for the quick response.
>
> However, this will not work for me since there can be any amount of
> child nodes under tables.
>
> What I need is a way of sequentially numbering the output for each foo1.
>
> On Tue, Aug 30, 2016 at 4:40 PM, Heiko Niemann
> kontakt@xxxxxxxxxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
> wrote:
>> You could save your strings (result) in a variable first and then do the
>> numbering in a second step (output):
>>
>> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>> xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs"
>> version="2.0">
>>   <xsl:output method="text" encoding="UTF-8"/>
>>   <xsl:template match="/">
>>
>>     <xsl:variable as="xs:string*" name="foos">
>>       <xsl:for-each select="1 to 5">
>>         <xsl:sequence select="concat('Data', .,' - ok')"/>
>>         <xsl:sequence select="concat('Data', .,' - not ok')"/>
>>       </xsl:for-each>
>>     </xsl:variable>
>>
>>     <xsl:value-of separator="{codepoints-to-string(10)}">
>>       <xsl:for-each select="$foos">
>>         <xsl:sequence select="concat(position(), '. ', .)"/>
>>       </xsl:for-each>
>>     </xsl:value-of>
>>
>>   </xsl:template>
>> </xsl:stylesheet>
>>
>>
>> Heiko
>>
>>
>>> Hello:
>>>
>>> I have a situation where I need to iterate over an element twice and
>>> output sequential numbers.
>>>
>>> I have two input files:
>>>
>>> First XML file. foo occurrence is 1 to infinity
>>>
>>> <root>
>>>
>>> <foo type="f1">
>>> <foo1>ok</foo1>
>>> <foo1>not ok</foo1>
>>> </foo>
>>>
>>> </root>
>>>
>>> Second XML file. tables can occur 1 to infinity. tab1 can also occur 1
>>> to infinity.
>>>
>>> <root1>
>>>
>>> <table ttype="f1">
>>>
>>> <tables>
>>> <tab1>
>>> Data1
>>> </tab1>
>>>
>>> <tab1>
>>> Data2
>>> </tab1>
>>>
>>>
>>> </tables>
>>> <tables>
>>> <tab1>
>>> ......
>>> </tab1>
>>> <tab1>
>>> Data3</tab1>
>>> </tables>
>>> </table>
>>> </root1>
>>>
>>> The logic is:
>>>
>>> for each /root/foo[@type = @ttype from 'root1']/foo1
>>>
>>> repeat tab1
>>>
>>> Desired output:
>>>
>>> 1. Data1 - ok
>>> 2.Data1 - not ok
>>> 3.Data2 - ok
>>> 4.Data2 - not ok
>>> 5.Data3 -ok
>>> 6.Data3-not ok
>>>
>>> I am able to get the individual 'tab1' elements to repeat. But my
>>> sequential numbering label is off. If I use position() within for-each
>>> it resets for every call in the for-each loop.
>>>
>>> I get:
>>>
>>> 1. Data1 - ok
>>> 2.Data1 - not ok
>>> 1.Data2 - ok
>>> 2.Data2 - not ok
>>> 1.Data3 -ok
>>> 2.Data3-not ok
>>>
>>>
>>> Any ideas or suggestions on how to make this work will be appreciated.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.