Subject: RE: Save the sorted xml in a variable
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 26 Jul 2005 10:18:12 +0100
|
You've got the data in the variable OK, I think: it's what you do with it
next that's the problem. You are processing the contents of the variable
like this:
<xsl:template match="/">
<xsl:apply-templates select="ms:node-set($sorted)/*"
mode="main"/>
</xsl:template>
<xsl:template match="item" mode="main">
<xsl:value-of select="."/>
</xsl:template>
which is going to display the textual content, just as you are observing.
I've forgotten what you actually want as your output, but try changing that
value-of to copy-of to see what's actually in there.
Michael Kay
http://www.saxonica.com/
> -----Original Message-----
> From: John Robb [mailto:john_ok@xxxxxx]
> Sent: 26 July 2005 08:24
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Save the sorted xml in a variable
>
> How is it possible to save the sorted xml in a variable and
> then apply
> to it some xsl elements.
> I'm using the following xsl but it doesn't work.I want to sort it by
> @sector and @subsector(see xml file bellow).In $sorted I just see the
> values of elements in <data> tags at the end/beginning.
> xsl:
> <?xml version="1.0"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:ms="urn:schemas-microsoft-com:xslt">
> <xsl:output media-type="xml"/>
> <xsl:variable name="sorted">
> <xsl:apply-templates mode="copy" select="data"/>
> </xsl:variable>
> <xsl:template match="@*|node()" mode="copy">
> <xsl:copy>
> <xsl:apply-templates select="@*|node()">
> <xsl:sort select="@sector"/>
> <xsl:sort select="@subsector"/>
> </xsl:apply-templates>
> </xsl:copy>
> </xsl:template>
> <xsl:template match="/">
> <xsl:apply-templates
> select="ms:node-set($sorted)/*" mode="main"/>
> </xsl:template>
> <xsl:template match="item" mode="main">
> <xsl:value-of select="."/>
> </xsl:template>
> </xsl:stylesheet>
>
> AND the XML :
> <?xml version="1.0" encoding="iso-8859-1" ?>
> <data>
> <item id="i1" sector="s1" subsector="u1">561</item>
> <item id="i10" sector="s3" subsector="u4">15</item>
> <item id="i22" sector="s2" subsector="u2">1234</item>
> <item id="i11" sector="s1" subsector="u2">123</item>
> <item id="i17" sector="s1" subsector="u3">165</item>
> <item id="i61" sector="s2" subsector="u1">346</item>
> <item id="i12" sector="s2" subsector="u5">3425</item>
> <item id="i2" sector="s3" subsector="u4">78</item>
> <item id="i14" sector="s3" subsector="u4">51</item>
> <item id="i21" sector="s1" subsector="u5">346</item>
> <item id="i39" sector="s3" subsector="u2">463</item>
> <item id="i44" sector="s2" subsector="u3">151</item>
> <item id="i89" sector="s1" subsector="u1">451</item>
> <item id="i81" sector="s2" subsector="u4">771</item>
> <item id="i36" sector="s2" subsector="u5">5654</item>
> <item id="i27" sector="s3" subsector="u3">362</item>
> <item id="i15" sector="s1" subsector="u5">234</item>
> <item id="i18" sector="s3" subsector="u2">73</item>
> <item id="i51" sector="s3" subsector="u5">567</item>
> <item id="i26" sector="s1" subsector="u4">17</item>
> <item id="i95" sector="s3" subsector="u5">67489</item>
> <item id="i13" sector="s1" subsector="u3">54</item>
> <item id="i71" sector="s1" subsector="u3">2</item>
> <item id="i23" sector="s2" subsector="u1">345</item>
> <item id="i7" sector="s2" subsector="u1">67</item>
> <item id="i80" sector="s1" subsector="u3">7754</item>
>
> <sector id="s1">Sector 1</sector>
> <sector id="s2">Sector 2</sector>
> <sector id="s3">Sector 3</sector>
>
> <subsector id="u1">Subsector 1</subsector>
> <subsector id="u2">Subsector 2</subsector>
> <subsector id="u3">Subsector 3</subsector>
> <subsector id="u4">Subsector 4</subsector>
> <subsector id="u5">Subsector 5</subsector>
> </data>
>
>
> ---
> GSM.By.COM - INTERNET-MAGAZIN SOTOWYH TELEFONOW STANDARTA GSM,
> AKSESSUAROW I ZAP^ASTEJ K NIM. {IROKIJ WYBOR, RAZUMNYE CENY,
> OPERATIWNAQ DOSTAWKA. rEMONT TELEFONOW. http://www.gsm.by.com
|