[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..
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|