Re: [xml] sorting with xmllib C/C++
- From: Michael Ludwig <milu71 gmx de>
- To: "xml gnome org" <xml gnome org>
- Subject: Re: [xml] sorting with xmllib C/C++
- Date: Mon, 21 Jun 2010 16:59:13 +0200
Frank Geisler schrieb am 21.06.2010 um 09:55 (-0400):
Cory,
Thanks for your reply. Yes, that is what I meant my sorting by attribute. I'll have a look into xslt. Would
you know what sorting algorithm is used?
No idea how it is implemented, but coding it in XSLT is straightforward:
# /tmp/sort.xml
<Urmel>
<eins>
<foo bar="33"/>
<foo bar="32"/>
<foo bar="34"/>
<foo bar="31"/>
</eins>
<zwei>
<foo bar="9"/>
<foo bar="7"/>
<foo bar="8"/>
</zwei>
</Urmel>
# /tmp/sort.xsl
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:template match="*[foo]">
<xsl:apply-templates select="*">
<xsl:sort select="@bar" data-type="number"/>
</xsl:apply-templates>
</xsl:template>
<!-- copy template -->
<xsl:template match="@*|node()">
<xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy>
</xsl:template>
</xsl:stylesheet>
$ xsltproc /tmp/sort.xsl /tmp/sort.xml
<?xml version="1.0"?>
<Urmel>
<foo bar="31"/><foo bar="32"/><foo bar="33"/><foo bar="34"/>
<foo bar="7"/><foo bar="8"/><foo bar="9"/>
</Urmel>
--
Michael Ludwig
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]