[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

What stylesheet might I use to parse the xml..

Subject: What stylesheet might I use to parse the xml..
From: Matthew Cordes <mcorde61@xxxxxxxxx>
Date: Sun, 9 Apr 2000 22:40:14 -0400
What stylesheet might I use to parse the xml..
Hello, I have some xml that I want to reorder, but leave in xml format 
via an xsl.  What I have right now isn't working, please help.


Starting xml:

<resultset>
    <result>
        <name>  Art </name>
        <age>   22  </age>
        <course>    mes-399 </course>
    </result>
    <result>
        <name>  Pat </name>
        <age>   22  </age>
        <course>    cos-399 </course>
    </result>
    <result>
        <name>  Stan </name>
        <age>   45  </age>
        <course>    mes-399 </course>
    </result>
    <result>
        <name>  Jimmy </name>
        <age>   23  </age>
        <course>    cos-399 </course>
    </result>
</resultset>


Here is the stylesheet I used,

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
    <courses>
        <xsl:apply-templates select="/resultset/result"/>
    </courses>
</xsl:template>

<xsl:template match="result">
    <course>
        <xsl:attribute name="title">
            <xsl:value-of select="course"/>
        </xsl:attribute>
		<student>
	        <name> <xsl:value-of select="name"/> </name>
	        <age> <xsl:value-of select="age"/> </age>
		</student>
    </course>
</xsl:template>
</xsl:stylesheet>


together these output: 


<?xml version="1.0" encoding="ISO-8859-1"?>
<courses>
	<course title="mes-399">
		<student>
			<name> Art </name>
			<age>22</age>
		</student>	
	</course>
	<course title="cos-399">
		<student>
			<name> Pat </name>
			<age>22</age>
		</student>
	</course>
	<course title="mes-399">
		<student>
			<name> Stan </name>
			<age>45</age>
		</student>
	</course>
	<course title="cos-399">
		<student>
			<name> Jimmy </name>
			<age>23</age>
		</student>
	</course>
</courses>


when I really wanted this output:

<?xml version="1.0" encoding="ISO-8859-1"?>
<courses>
	<course title="mes-399">
		<student>
			<name> Art </name>
			<age>22</age>
		</student>
		<student>
			<name> Stan </name>
			<age>45</age>
		</student>
	</course>
	<course title="cos-399">
		<student>
			<name> Pat </name>
			<age>22</age>
		</student>	
		<student>
			<name> Jimmy </name>
			<age>23</age>
		</student>	
	</course>
</courses>

Notice how the desired xml above is grouped by course, while the real
output is not.  Can anyone help me do it this way?

Perhaps also, some kind of xsl that would allow me to compress nodes with
the same name would also work (e.g., above, <course title="cos-399">
appears twice, but I really only want it once ).

Thanks for reading this,

-matt


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.