xsl-list
[Top] [All Lists]

Re: [xsl] xsl:perform-sort sequence problem

2007-10-22 05:09:32
At 2007-10-22 13:05 +0200, Merico Raffaele wrote:
I am using SaxonB 8.9 and I have the following xsl:perform-sort/sequence
problem.

Actually your problem is elsewhere.

When I try to sort the same sequence the distinct-values become one single
string:

Actually, your distinct-values is still a sequence ... but your variable is a temporary tree:

<xsl:variable name="result">
        <xsl:perform-sort 
select="distinct-values($data/item/departure[(_at_)date
eq '2007-10-22']/returning/@date)">
                <xsl:sort/>
        </xsl:perform-sort>
</xsl:variable>
<xsl:value-of select="count($result)"/>

And above you are counting your temporary trees.

<xsl:value-of select="$result" separator=", "/>

=> 1
=> 2007-10-22 2007-10-23 2007-10-24

Can any body please helping me to clarify my misunderstanding of the
xsl:perform-sort.

You need to better understand your variable declarations.

Instead of a temporary tree, you want a variable of strings. Therefore, declare your variable with:

   as="xsd:string+"

I hope the working answer below helps.

. . . . . . . . . . . Ken

t:\ftemp>type merico.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                xmlns:xsd="http://www.w3.org/2001/XMLSchema";
                exclude-result-prefixes="xsd"
                version="2.0">

<xsl:output method="text"/>

<xsl:template match="/">
<xsl:variable name="data">
        <item id="1">
                <departure date="2007-10-22">
                        <returning date="2007-10-23"/>
                        <returning date="2007-10-24"/>
                </departure>
        </item>
        <item id="2">
                <departure date="2007-10-22">
                        <returning date="2007-10-22"/>
                        <returning date="2007-10-24"/>
                </departure>
        </item>
</xsl:variable>

Result 1:
<xsl:variable name="result1"
select="distinct-values($data/item/departure[(_at_)date eq
'2007-10-22']/returning/@date)"/>
<xsl:value-of select="count($result1)"/>: <xsl:text/>
<xsl:value-of select="$result1" separator=", "/>


Result 2:
<xsl:variable name="result2">
        <xsl:perform-sort 
select="distinct-values($data/item/departure[(_at_)date
eq '2007-10-22']/returning/@date)">
                <xsl:sort/>
        </xsl:perform-sort>
</xsl:variable>
<xsl:value-of select="count($result2)"/>: <xsl:text/>
<xsl:value-of select="$result2" separator=", "/>

Result 3:
<xsl:variable name="result3" as="xsd:string+">
        <xsl:perform-sort 
select="distinct-values($data/item/departure[(_at_)date
eq '2007-10-22']/returning/@date)">
                <xsl:sort/>
        </xsl:perform-sort>
</xsl:variable>
<xsl:value-of select="count($result3)"/>: <xsl:text/>
<xsl:value-of select="$result3" separator=", "/>


</xsl:template>

</xsl:stylesheet>
t:\ftemp>xslt2 merico.xsl merico.xsl con


Result 1:
3: 2007-10-23, 2007-10-24, 2007-10-22


Result 2:
1: 2007-10-22 2007-10-23 2007-10-24

Result 3:
3: 2007-10-22, 2007-10-23, 2007-10-24
t:\ftemp>


--
Comprehensive in-depth XSLT2/XSL-FO1.1 classes: Austin TX,Jan-2008
World-wide corporate, govt. & user group XML, XSL and UBL training
RSS feeds:     publicly-available developer resources and training
G. Ken Holman                 mailto:gkholman(_at_)CraneSoftwrights(_dot_)com
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Cancer Awareness Jul'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>