Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 7th, 2006, 03:14 AM
Friend of Wrox
Points: 718, Level: 10
Points: 718, Level: 10 Points: 718, Level: 10 Points: 718, Level: 10
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: Ennis, Clare, Ireland.
Posts: 131
Thanks: 10
Thanked 0 Times in 0 Posts
Default Child Node Output

Hi,

I'm trying to run my XSL code as efficiently as possible. I have an extract from my XML file (below):

Code:
<Doc>
<Document>
<Test Code="0001">
        <UOM>%</UOM>
        <Desc>Moisture</Desc>
    <Set No="1">
        <Targ>12.33</Targ>
        <Min>10.83</Min>
        <Max>13.83</Max>
    </Set>
    <Set No="2">
        <Targ>12.33</Targ>
        <Min>8.00</Min>
        <Max>15.00</Max>
    </Set>
    <Set No="3">
        <Min>10.00</Min>
        <Max>14.80</Max>
    </Set>
    <SampRes No="1">
        <Lab>CEN</Lab>
        <Fail>N</Fail>
    </SampRes>
</Test>
<Test Code="0005">
    <UOM>%</UOM>
    <Desc>Crude Protein</Desc>
    <Set No="1">
        <Targ>17.81</Targ>
        <Min>16.81</Min>
        <Max>18.81</Max>
    </Set>
    <Set No="2">
        <Targ>17.80</Targ>
        <Min>16.02</Min>
        <Max>21.36</Max>
    </Set>
    <Set No="3">
        <Targ>17.81</Targ>
        <Min>16.03</Min>
        <Max>21.37</Max>
    </Set>
    <SampRes No="1">
        <Lab>CEN</Lab>
        <Fail>N</Fail>
    </SampRes>
</Test>
</Document>
</Doc>
How do I loop through each '<Test Code="xxxx">' and display each child node and the relevant fields? I understand the 'For Each' statement, but I wonder whether there is a more automated system.

Code:
<xsl:template name="Test">
    <xsl:for-each select="*//Test">
        <xsl:element name="Test">
            <xsl:attribute name="Code">
                <xsl:value-of select="@*"/>
The above obviously produces:

Code:
<Test Code="0001" />
<Test Code="0005" />
How do I retrieve and display each child node (and all other dependant fields) for each 'Test'?

For Example
How do I return the individual values for?
The <UOM> value
The <Set> Value
The <Target> value

Neal

A Northern Soul
__________________
Neal

A Northern Soul




Similar Threads
Thread Thread Starter Forum Replies Last Post
Process all nested child node tims XSLT 4 April 8th, 2008 07:45 AM
The reference node is not a child of this node.XSL XMLUser XSLT 2 February 25th, 2008 05:22 AM
how to append child node after an node in XML + C# vishnu108mishra XML 5 November 13th, 2007 05:30 AM
How to count the child node suri_1811 XSLT 6 November 10th, 2006 04:51 PM
Copying Source Node attributes to output node pvsat XSLT 2 November 3rd, 2005 09:46 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.