Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 October 30th, 2008, 01:00 PM
Authorized User
 
Join Date: Sep 2008
Posts: 56
Thanks: 0
Thanked 1 Time in 1 Post
Default not able to print child nodes upto 2 level

<root>
<test title="Home" link="4" >
<test title="about usUS" link="aboutUS" />
<test title="historyUS" link="historyUS" />
<test title="infoUS" link="infoUS" >
     <test title="pressUS" link="pressUS" />
     <test title="newsUS" link="newsUS" />
</test>
</test>

<test title="UK" link="4" >
<test title="about usuk" link="aboutuk" />
<test title="historyuk" link="historyuk" />
<test title="infouk" link="infouk" >
     <test title="pressuk" link="pressuk" />
     <test title="newsuk" link="newsuk" />
</test>
</test>
</root>



<xsl:template match="/">
        [list]
            <xsl:for-each select="./test[@title='Home']/test">
                <li><xsl:value-of select="@title"></xsl:value-of></li>
                <xsl:if test="test">
                [list]
                    <xsl:for-each select="./test">
                        <li><xsl:value-of select="@title"></xsl:value-of></li>
                        </xsl:for-each>
                </ul>
                    </xsl:if>
                    </xsl:for-each>
        </ul>

        [list]
            <xsl:for-each select="./test[@title='UK']/test">
                <li><xsl:value-of select="@title"></xsl:value-of></li>
                <xsl:if test="test">
                [list]
                    <xsl:for-each select="./test">
                        <li><xsl:value-of select="@title"></xsl:value-of></li>
                        </xsl:for-each>
                </ul>
                    </xsl:if>
                    </xsl:for-each>
        </ul>

    </xsl:template>

above is my XML and XSLT.

when I run the query it fails not sure whats going on. if I remove the whole xsl:for-each for UK
I am able to get HOME etc printed just fine but when I use the same for UK it fails. This is the output I am looking for.
[list]
    <li>about us</li>
    <li>history</li>
    <li>info</li>
    [list]
        <li>press</li>
        <li>news</li>
    </ul>
</ul>[list]
    <li>about usuk</li>
    <li>historyuk</li>
    <li>infouk</li>
    [list]
        <li>pressuk</li>
        <li>newsuk</li>
    </ul>
</ul>
 
Old October 30th, 2008, 01:06 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Your sample input has two root elements, that is not allowed in a well-formed XML document so that could be a problem you encounter.

--
  Martin Honnen
  Microsoft MVP - XML
 
Old October 30th, 2008, 01:09 PM
Authorized User
 
Join Date: Sep 2008
Posts: 56
Thanks: 0
Thanked 1 Time in 1 Post
Default

I apologize I just made the correct change to my XML please see the above XML again. thanks.

 
Old October 30th, 2008, 01:10 PM
Authorized User
 
Join Date: Sep 2008
Posts: 56
Thanks: 0
Thanked 1 Time in 1 Post
Default

I got it. Thanks again for your help Martin. You guys are the best. :D
I simply added root before the test and its working





Similar Threads
Thread Thread Starter Forum Replies Last Post
not able to print out the child nodes eruditionist XSLT 7 October 30th, 2008 10:33 AM
Accessing higher level nodes from a template mikeymikey XSLT 3 January 3rd, 2008 09:14 PM
Retrieveal of child nodes.... nathilson21 Classic ASP XML 0 May 7th, 2007 04:54 AM
Trying to group child nodes aalbetski XSLT 3 November 18th, 2006 01:29 PM
counting child nodes Tomi XSLT 1 September 6th, 2006 03:26 AM





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