Re: [xml] sorting with xmllib C/C++

Frank Geisler schrieb am 21.06.2010 um 09:55 (-0400):

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
    <foo bar="33"/>
    <foo bar="32"/>
    <foo bar="34"/>
    <foo bar="31"/>
    <foo bar="9"/>
    <foo bar="7"/>
    <foo bar="8"/>

# /tmp/sort.xsl
<xsl:stylesheet version="1.0"
  <xsl:output indent="yes"/>

  <xsl:template match="*[foo]">
    <xsl:apply-templates select="*">
      <xsl:sort select="@bar" data-type="number"/>

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

$ xsltproc /tmp/sort.xsl /tmp/sort.xml
<?xml version="1.0"?>
        <foo bar="31"/><foo bar="32"/><foo bar="33"/><foo bar="34"/>
        <foo bar="7"/><foo bar="8"/><foo bar="9"/>

Michael Ludwig

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]