all groups > dotnet xml > august 2004 >
You're in the

dotnet xml

group:

XSLT Doing my brain in....


XSLT Doing my brain in.... Paul King
8/26/2004 3:50:41 PM
dotnet xml: Hi there,

I have a raw XML order file with the following structure

<root>
<header>
<body>

Ok the HEADER contains details about the XML msg and its originator etc -
pretty pointless stuff
The BODY however contains multiple Orders with descriptions and QTY's etc.

I have such designed an XSL basic sheet which allows me to fetch XML data
into a table using the FOR-EACH routine.

For example here is a little snippet:

<xsl:for-each
select="Orders_Envelope/body/Orders/OrderLines/OrderLineDetail">
<tr>
<td><xsl:value-of select="Product/Description"/></td>
</tr>
</xsl:for each>

The resulting page only however fetches back the first product description
from the file not others. Why is this?

Any help would be great
Paul

Re: XSLT Doing my brain in.... Oleg Tkachenko [MVP]
8/29/2004 6:12:07 PM
[quoted text, click to view]

That's how xsl:value-of instruction works - it takes the first selected
node in document order and outputs its string value. If you need all
Product Descriptions, have a loop over them.

--
Oleg Tkachenko [XML MVP]
Re: XSLT Doing my brain in.... Jason Sobell
9/2/2004 12:01:04 AM
Hi Paul,
The appropriate way to do this is to use the apply-templates method, so
you have something like:

<xsl:for-each
select="Orders_Envelope/body/Orders/OrderLines/OrderLineDetail">
<tr>
<xsl:apply-templates select="Product/Description"/>
</tr>
</xsl:for each>

<xsl:template match="Description">
<td><xsl:value-of select="."/></td>
</xsl:template>

Without seeing your source XML it's difficult to say exactly, but you
rarely need to use the for-each construct, as the template will be called
for every node that matches the select= statement.

Cheers,
Jason

[quoted text, click to view]
Re: XSLT Doing my brain in.... Paul King
9/6/2004 4:35:02 PM
Thanks guys - I think its just my inexperience with this technology

I think I have got it covered.

Cheers
Paul.

[quoted text, click to view]

AddThis Social Bookmark Button