Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: sorting nodes [Thread Next] Re: sorting nodesTo: 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/
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
