Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looping with XSL 1

Status
Not open for further replies.

msturges

Programmer
Mar 29, 2001
32
0
0
ZA
Hi all,

Need some help here. I have a xml document that looks like this :

<?xml version=&quot;1.0&quot;?>
<?xml-stylesheet href=&quot;WAstylesheet.xsl&quot; type=&quot;text/xsl&quot;?>
<order no=&quot;0001&quot;>
<Sender>Sender</Sender>
<orderNo>0001</orderNo>
<orderDate>2002/01/22</orderDate>
<orderPoint>Order Point</orderPoint>
<invoicePoint>Invoice Point</invoicePoint>
<supplierPoint>Supplier Point</supplierPoint>
<deliveryDates>
<earliest>2002/01/22</earliest>
<latest>2002/01/31</latest>
</deliveryDates>
<transactionCode>Transaction Code</transactionCode>
<narrative>Order Narrative 1 </narrative>
<narrative>Order Narrative 2</narrative>
<narrative>Order Narrative 3</narrative>

<Product id=&quot;001-000001&quot;>
<Prod_Code>001-000001</Prod_Code>
<Qty_Ordered>1</Qty_Ordered>
<Description>First Item</Description>
<Price>R10.00</Price>
<prTotal>R10.00</prTotal>
</Product>
<orTotal>210</orTotal>
</order>

The narrative line loops an unknown amount of times.
In my XSL file I need to loop through these narrative lines and collect all the values. I thought the code should look something like this:

<xsl:for-each selecet=&quot;narrative&quot;>
<xsl:value-of select=&quot;narrative&quot;/> <br/>
</xsl:for-each>

but this does not work. The closest I've managed to get is to bring only the first occurance down by leaving the xsl:for-each tags out. But, that helps me jack.

Any tips would be greatly appreciated.

Thanks alot
Mike
 
Use for-each if you loop through each narrative node. If you want to add the all up, use the xpath function sum():

<xsl:value-of select=&quot;sum(narrative)&quot;/>

Jordi Reineman
 
I tried to use the sum() method, as you suggested, but got the following response:

Unknown method. -->sum(narrative<--)

any explanation why?
Is there perhaps a xmlns declaration that I need to add to the proccessing instructions?

thanks
Mike
 
msturges --

If I undersdtand what you are trying to do correctly, you are simply looking to display each narrative line in your output. Since the <xsl:for-each> statement has already selected you &quot;Narrative&quot; node, you can not re-select it inside the loop.

This, I think, should do what you want...

<xsl:for-each select=&quot;narrative&quot;>
<xsl:value-of select=&quot;.&quot;/>
</xsl:for-each>

Note the select statement in the value-of -- That means &quot;the current node&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top