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 4th, 2010, 10:54 AM
Authorized User
 
Join Date: Sep 2008
Posts: 56
Thanks: 0
Thanked 1 Time in 1 Post
Default Display all nodes of an XML

<?xml version="1.0" encoding="UTF-8"?>
<root>
<node category="A" name="levelOne" title="Home" link="/index.jsp">
<node category="B" name="levelTwo" title="Residential" link="/levelTwo/index.jsp">
<node category="A" name="levelThree" title="Food Waste" link="/levelThree/food/food-waste.jsp">
<node category="A" name="levelFour" title="junk Waste" link="/levelFour/food/junk.jsp"/>
<node category="A" name="levelFour" title="PC Waste" link="/levelFour/food/pcwaste.jsp"/>
</node>
</node>
<node category="A" name="levelTwo" title="Residential II" link="/levelTwo/index.jsp">
<node category="B" name="levelThree" title="Health Care" link="/levelThree/health/index.jsp">
<node category="A" name="levelFour" title="med Disposal" link="/levelFour/health/test.jsp"/>
</node>
</node>
<node category="C" name="levelTwo" title="Residential III" link="/levelTwo/index.jsp">
<node category="B" name="levelThree" title="Curb" link="/levelThree/health/index.jsp">
<node category="B" name="levelFour" title="Site Disposal" link="/levelFour/health/testing.jsp"/>
<node category="B" name="levelFour" title="car Disposal" link="/levelFour/health/car.jsp"/>
</node>
</node>
</node>

</root>

Based on the XML above how do I get this output.



(Residential)
Food Waste
(1)junk Waste
(2)PC waste

(Residential II)
Health Care
(1)med Disposal

(Residential III)
Curb
(1)Site Disposal
 
Old October 4th, 2010, 11:54 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Code:
   <xsl:template match="node[@name='levelTwo']">
	     (<xsl:value-of select="@title"/>)
	     <xsl:apply-templates/>
	     <xsl:text>
</xsl:text>
   </xsl:template>

   <xsl:template match="node[@name='levelThree']">
	     <xsl:value-of select="@title"/>
	     <xsl:apply-templates/>
   </xsl:template>

   <xsl:template match="node[@name='levelFour']">
	     (<xsl:value-of select="position()"/>) <xsl:value-of select="@title"/>
	     <xsl:apply-templates/>
   </xsl:template>
   
	  <xsl:template match="text()"/>
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Display only unique Nodes kylektran XSLT 1 July 17th, 2009 08:41 AM
How can I display parent & child nodes if XML .... vishnu108mishra ASP.NET 2.0 Basics 0 November 17th, 2007 07:45 AM
HOW TO: Display specified # of nodes kwilliams XSLT 2 October 5th, 2005 11:04 AM
Display nodes from xml nambati XSLT 2 September 17th, 2004 07:57 AM
How to display all nodes in my Network using VB 6 harini19 VB How-To 1 January 16th, 2004 10:10 AM





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