Page 1 of 1

loop in loop

Posted: Thu Jan 18, 2007 9:48 pm
by pero
hi,

i'm beginer in xsl transformation. i editing xsl with altova style vision
I have one problem with working with two nodes.

<root>
<Items>
<ItemID>1<ItemID>
<ItemDes>A<ItemDes>
</Items>
<Items>
<ItemID>2<ItemID>
<ItemDes>B<ItemDes>
</Items>
<DetailDes>
<DetItemID>1</DetItemID>
<Detail>HI<Detail>
</DetailDes>
<DetailDes>
<DetItemID>2</DetItemID>
<Detail>tnx<Detail>
</DetailDes>
</root>

I would like to make a teble(loop items) and in this table i make another loop (loop DetailDes). in table (items) i need to displey only items ItemID = DetItemID.

example table:
----------------------------------
Item ID | Description |
---------------------------------
1 | A|
details: HI
--------------------------------
2 | B|
details: tnx
--------------------------------

tnx for any help[/code]

Posted: Thu Jan 18, 2007 11:49 pm
by george
Please note that this forum is a support channel for oXygen XML editor which is a competitor for the product you are using. We cannot provide you advise on how to use that product, we advise you to direct your further questions to the support channels of that product.

Note that your sample input is not XML, it is not wellformed. The corrected input looks like

Code: Select all


<root>
<Items>
<ItemID>1</ItemID>
<ItemDes>A</ItemDes>
</Items>
<Items>
<ItemID>2</ItemID>
<ItemDes>B</ItemDes>
</Items>
<DetailDes>
<DetItemID>1</DetItemID>
<Detail>HI</Detail>
</DetailDes>
<DetailDes>
<DetItemID>2</DetItemID>
<Detail>tnx</Detail>
</DetailDes>
</root>
A sample stylesheet that generates a HTML table similar with the one from your description from the sample XML is below

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="root">
<html>
<head><titel>Sample</titel></head>
<body>
<table border="1">
<tr><th>ItemID</th><th>Description</th></tr>
<xsl:apply-templates select="Items"/>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="Items">
<tr>
<td><xsl:value-of select="ItemID"/></td>
<td><xsl:value-of select="ItemDes"/></td>
</tr>
<tr>
<td colspan="2">
<xsl:text>details: </xsl:text>
<xsl:value-of select="../DetailDes[DetItemID=current()/ItemID]/Detail"/>
</td>
</tr>
</xsl:template>

</xsl:stylesheet>
Regards,
George