xsl-list
[Top] [All Lists]

Re: Sorting problems [was: Choosing different sorts]

2004-07-16 04:16:23


      <xsl:for-each select="file">
        <xsl:sort select="*[name(.) = $sortkey]"/>   

That means that your sort key is determined by selecting a child element
of file (that's what * means) whose name is equal to the string value of
$sortkey.

but for example if $sort='design' then $sortkey is (a result tree
fragment with text node the) string 'sml:meta/sml:designer/sml:name'

and there is no child element with name that string (it isn't a legal
XML+namespace eleemt name as it's got "/" in it and more than one ":" ).

You don't want to sort on child elements of file at all you presumably
want to sort on the element with Xpath sml:meta/sml:designer/sml:name
relative to file. But there is a big difference between the string
'sml:meta/sml:designer/sml:name' and an Xpath, and no easy way in xslt
to go from one to the other, just as in C or Java (or most other
languages) it's hard to go from the string "x + 1" to incrementing the
variable x by 1, you have to write (or find) a parser for the language to
interpret the string.

You presumably want something like


     <xsl:for-each select="file">
        <xsl:sort
        select="sml:scenario[$sort!='design'][$sort!='stat']/sml:name
              | sml:meta[$sort='design']/sml:designer/sml:name
              | sml:scenario[$sort='stat']/@status"/>

Note here I have only used XPaths, not strings or equivalently element
content.

This is a FAQ...

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________


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