Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries [Thread Prev] >Thread Next - Re: Help! How do I sort my data, and keep the root's attributes at the same time? Help! How do I sort my data, and keep the root's attributes at the same time?To: NULL Date: 8/3/2004 6:41:00 PM I'm trying to sort my XML which looks like:
<?xml version="1.0" encoding="UTF-16"?>
<LABORATORY case="234" project="TR43" Type="A2">
<CLIENT Name="XXXX" LName="XXXX"/>
<CLIENT Name="WWWW" LName="WWWW"/>
<CLIENT Name="QQQQ" LName="QQQQ"/>
<CLIENT Name="RRRR" LName="RRRR"/>
<CLIENT Name="TTTT" LName="TTTT"/>
<CLIENT Name="DDDD" LName="DDDD"/>
<DENTALUNITS Number="4" date="10/May/04">DATA GOES
HERE</DENTALUNITS>
<DENTALUNITS Number="4" date="14/Apr/04">DATA GOES
HERE</DENTALUNITS>
<DENTALUNITS Number="4" date="17/Jun/04">DATA GOES
HERE</DENTALUNITS>
<DENTALUNITS Number="4" date="20/Jan/04">DATA GOES
HERE</DENTALUNITS>
<DENTALUNITS Number="4" date="23/Mar/04">DATA GOES
HERE</DENTALUNITS>
<DENTALUNITS Number="4" date="29/Dec/04">DATA GOES
HERE</DENTALUNITS>
</LABORATORY>
The problem is that when I try to sort my data, I end up with the same
XML as the source.
I suspect this is due to the copy-of select="@*|."/ I'm using, which
is copying the whole tree. So I tried using xsl:copy to only copy the
root, and then sort the child, but that didn't work either. This is my
XSL:
<?xml version='1.0'?>
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="LABORATORY|LABORATORY/CLIENT">
<xsl:copy>
<xsl:copy-of select="@*|."/>
<xsl:apply-templates select="LABORATORY/DENTALUNITS">
<xsl:sort select="substring(@date,8,2)" data-type="number"
order="ascending"/> <xsl:sort select="substring(@date,4,3)"
data-type="text" order="ascending"/> <xsl:sort
select="substring(@date,1,2)" data-type="number" order="ascending"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="LABORATORY/DENTALUNITS">
<xsl:copy-of select="@*|."/>
</xsl:template>
</xsl:transform>
All I need to do is to copy the CLIENT data as it is, and to sort the
DENTALUNITS data by date. I have tried different approaches to do
this, but when I get the attributes of LABORATORY nothing else is
done. I get someting like:
<?xml version="1.0" encoding="UTF-16"?>
<LABORATORY case="234" project="TR43" Type="A2">
</LABORATORY>
This is the XSL I used in this case:
<?xml version='1.0'?>
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<xsl:for-each select="LABORATORY">
<LABORATORY case="{@case}" project="{@project}" Type="{@Type}">
<xsl:apply-templates select="LABORATORY/CLIENT">
</xsl:apply-templates>
<xsl:apply-templates select="LABORATORY/DENTALUNITS">
<xsl:sort select="substring(@date,8,2)" data-type="number"
order="ascending"/>
<xsl:sort select="substring(@date,4,3)" data-type="text"
order="ascending"/>
<xsl:sort select="substring(@date,1,2)" data-type="number"
order="ascending"/>
</xsl:apply-templates>
</LABORATORY>
</xsl:for-each>
</xsl:template>
<xsl:template match="LABORATORY/CLIENT">
<xsl:copy-of select="."/>
</xsl:template>
<xsl:template match="LABORATORY/DENTALUNITS">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:transform>
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
