Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: sorting nodes >Thread Next - Re: sorting nodes Re: sorting nodesTo: NULL Date: 4/4/2008 7:46:00 AM "Anthony Jones" <Ant@y...> wrote in message news:%23i3k2jilIHA.3512@T...... > "tshad" <tshad@d...> wrote in message > news:%23NAEdJelIHA.3940@T...... >> I can't seem to get my results to be formatted. >> >> I have the following xml: >> >> <?xml version="1.0" encoding="utf-8"?> >> <Report> >> <data> >> <form name="order" primary="false"> >> <tag name="DUEDATE" flags="1" format="4096">12/01/2007</tag> >> </form> >> <form name="title" primary="false"> >> <tag name="CITY_STATE_ZIP.1" flags="0" format="12288">Surprise, AZ >> 85374-2525</tag> >> </form> >> <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> >> <section type="subject" number="0"> >> <tag name="CITY.1" flags="0" format="0">Surprise</tag> >> </section> >> <section type="salescomp" number="1"> >> <tag name="GS_AGE.1" flags="0" format="0">9 Yrs.</tag> >> </section> >> <section type="salescomp" number="2"> >> <tag name="GS_AGE.1" flags="0" format="0">12 Yrs.</tag> >> </section> >> </form> >> </data> >> </Report> >> >> I also have the following xslt file: >> >> <xsl:stylesheet version="1.0" >> xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >> exclude-result-prefixes="xsi"> >> <xsl:output method="xml" indent="yes"/> >> <xsl:template match="/*"> >> <xsl:copy> >> <xsl:apply-templates select="data/form/tag | data/form/section/tag"> >> <xsl:sort select="form/@primary" order="ascending"/> >> </xsl:apply-templates>/> >> </xsl:copy> >> </xsl:template> >> <xsl:template match="tag"> >> <form> >> <sectionNumber> >> <xsl:value-of select="ancestor::section/@number"/> >> </sectionNumber> >> <primary> >> <xsl:value-of select="ancestor::form/@primary"/> >> </primary> >> <formName> >> <xsl:value-of select="ancestor::form/@name"/> >> </formName> >> <tagName> >> <xsl:value-of select="@name"/> >> </tagName> >> <flags> >> <xsl:if test="not(@flags)"> >> <xsl:attribute name="xsi:nil">true</xsl:attribute> >> </xsl:if> >> <xsl:value-of select="@flags"/> >> </flags> >> <format> >> <xsl:if test="not(@format)"> >> <xsl:attribute name="xsi:nil">true</xsl:attribute> >> </xsl:if> >> <xsl:value-of select="@format"/> >> </format> >> <value> >> <xsl:value-of select="."/> >> </value> >> </form> >> </xsl:template> >> </xsl:stylesheet> >> >> My sort doesn't seem to work. Regardless, whether I use ascending or >> descending, I get: >> >> <?xml version="1.0" encoding="utf-8"?> >> <Report> >> <data> >> <form name="order" primary="false"> >> <tag name="DUEDATE" flags="1" format="4096">12/01/2007</tag> >> </form> >> <form name="title" primary="false"> >> <tag name="CITY_STATE_ZIP.1" flags="0" format="12288">Surprise, AZ >> 85374-2525</tag> >> </form> >> <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> >> <section type="subject" number="0"> >> <tag name="CITY.1" flags="0" format="0">Surprise</tag> >> </section> >> <section type="salescomp" number="1"> >> <tag name="GS_AGE.1" flags="0" format="0">9 Yrs.</tag> >> </section> >> <section type="salescomp" number="2"> >> <tag name="GS_AGE.1" flags="0" format="0">12 Yrs.</tag> >> </section> >> </form> >> </data> >> </Report> >> >> It is in the order of the original file. Why is that? >> > > The context nodes for the sort path will be the nodes selected in the > apply-templates select, IOW they will all be tag elements. You need:- > > <xsl:sort path="ancestor::form/@primary" > Can you do 2 sorts? Sort on @primary and on ancestor::section/@number? Thanks, Tom > > -- > Anthony Jones - MVP ASP/ASP.NET > > | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
