This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Sorting XML with XSL, output as XML


Hello Ernst,

again a identity transformation will help:

<xsl:template match="*|text()|@*">
   <xsl:copy>
     <xsl:apply-templates select="*|text()|@*"/>
   </xsl:copy>
</xsl:template>

Then you need to add a special template for the book elements.

<xsl:template match="book">
   <xsl:copy>
     <xsl:apply-templates select="@*"/>
     <xsl:apply-templates select="chapter">
       <xsl:sort select="*[name()=$sortfield]" order="{$sortorder}" />
     </xsl:apply-templates>
   </xsl:copy>
</xsl:template>

Regards,

Joerg

Ernst Wolthaus schrieb:
> Hi all,
> 
> I'm new it this so I hope I'm posting this message the right way. 
> Anyway...
> 
> I've got a HTML-pager with a table, with a data island, so the XML data 
> is bounded in the table by Datafld and Datasrc. Now I want to sort the 
> XML-data by an XSL-file and a XSL:SORT command. However, this needs to 
> be generic so I can use the same XSL for all kinds of XML, because else 
> I have to make a XSL for every XML.
> 
> Example:
> 	<?xml version="1.0"?>
> 	<book>
> 	<chapter>
> 	<number>2</number>
> 	<title>two</title>
> 	<paragraph>text 2</paragraph>
> 	</chapter>
> 	<chapter>
> 	<number>1</number>
> 	<title>one</title>
> 	<paragraph>text 1</paragraph>
> 	</chapter>
> 	</book>
> 
> How do I sort this data by e.g. Number or by Title in a generic way. It's 
> needs to output the "same" XML but sorted like:
> 
> 	<?xml version="1.0"?>
> 	<book>
> 	<chapter>
> 	<number>1</number>
> 	<title>one</title>
> 	<paragraph>text 1</paragraph>
> 	</chapter>
> 	<chapter>
> 	<number>2</number>
> 	<title>two</title>
> 	<paragraph>text 2</paragraph>
> 	</chapter>
> 	</book>
> 
> I know how to sort with xsl:param and <xsl:sort 
> select="@*[name()=$sortfield]" order="{$sortorder}" /> but how do I get 
> the XML back like the XML described above...???
> 
> I've spend a lot of this on this so I would greatly appreciate any 
> help!!
> 
> Thanks,
> Ernst Wolthaus


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]