Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: sorting nodes

From: "tshad" <tshad@----------.--->
To: NULL
Date: 4/4/2008 9:54:00 AM


"Martin Honnen" <mahotrash@y...> wrote in message 
news:%23fldSZmlIHA.1744@T......
> tshad wrote:
>
>>>>    <xsl:apply-templates select="data/form/tag | data/form/section/tag">
>>>>     <xsl:sort select="form/@primary" order="ascending"/>
>>>>    </xsl:apply-templates>/>
>
>
>> Can you do 2 sorts?
>>
>> Sort on @primary and on ancestor::section/@number?
>
> Yes, you simply need to use two xsl:sort elements e.g.
>   <xsl:apply-templates select="...">
>     <xsl:sort select="@primary"/>
>     <xsl:sort select="ancestor::section/@number"/>
>   </xsl:apply-templates>
> that way the first xsl:sort defines the primary sort key, the second 
> xsl:sort the secondary sort key.
>
>
Worked great.

I assume that the elements/nodes are selected first based on the "select=", 
then the sort is applied to those, then the templates are applied.

At least that is how it seems to work.

Also, during the sort, all the nodes that don't apply will be blank and are 
considered the lowest.

In this example:

      <form name="1004_05" primary="true">
        <section type="options" number="0">
          <tag name="OPT_TYPE_OF_APPRAISAL.1" flags="1" 
format="12288">Summary Appraisal Report</tag>
        </section>
          <tag name="CITY.1" flags="0" format="0">Surprise</tag> 
<-- no section
          <tag name="STATE.1" flags="0" format="0">AZ</tag> 
<-- no section
          <tag name="COUNTY.1" flags="0" format="0">Maricopa</tag> 
<-- no section
        <section type="salescomp" number="1">
          <tag name="GS_AGE.1" flags="0" format="0">9 Yrs.</tag>
          <tag name="GS_SITE.1" flags="0" format="0">6,100 SqFt</tag>
          <tag name="GS_VIEW.1" flags="1" format="0">Average</tag>
        </section>
        <section type="salescomp" number="2">
          <tag name="GS_AGE.1" flags="0" format="0">12 Yrs.</tag>
          <tag name="GS_SITE.1" flags="0" format="0">4,840 SqFt</tag>
          <tag name="GS_VIEW.1" flags="1" format="0">Good</tag>
        </section>
      </form>

And applying this:

   <xsl:apply-templates select="appraisal/data/form/tag | 
appraisal/data/form/section/tag">
    <xsl:sort select="ancestor::form/@primary" order="ascending"/>
    <xsl:sort select="ancestor::section/@number" order="descending" 
data-type="number"/>
   </xsl:apply-templates>

The 3 nodes that have no section, will be at the bottom and if I change the 
order of the @number to ascending, they will be at the top.

Thanks,

Tom
>
> -- 
>
> Martin Honnen --- MVP XML
> http://JavaScript.FAQTs.com/ 




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent