scope of xsl:sort

Discussion in 'XML' started by R, Mar 24, 2005.

  1. R

    R Guest

    Hello everybody.

    I was sorting all my XML data with for-each and sort.
    But there were few cases that I didn't want to sort my data.

    so I added nosort attribute - if given and set to '1' don't sort.

    I wrote this:

    <xsl:for-each select="field">
    <xsl:if test="not(../data/@nosort='1')">
    <xsl:sort select="description"/>
    </xsl:if>
    <!-- the rest of the template here -->
    </xsl:for-each>

    but this XSLT returns me an error:

    Warning: xsl:sort : improper use this should not be reached in
    /home/xh/workspace/ERS_new/engine/classes/XML.inc.php on line 138
    (paresed with PHP5 DOM)

    how can I make my nosort attribute work?

    thanks for any help

    best regards
    R
     
    R, Mar 24, 2005
    #1
    1. Advertising

  2. R wrote:


    > I was sorting all my XML data with for-each and sort.
    > But there were few cases that I didn't want to sort my data.
    >
    > so I added nosort attribute - if given and set to '1' don't sort.
    >
    > I wrote this:
    >
    > <xsl:for-each select="field">
    > <xsl:if test="not(../data/@nosort='1')">
    > <xsl:sort select="description"/>
    > </xsl:if>
    > <!-- the rest of the template here -->
    > </xsl:for-each>
    >
    > but this XSLT returns me an error:
    >
    > Warning: xsl:sort : improper use this should not be reached in
    > /home/xh/workspace/ERS_new/engine/classes/XML.inc.php on line 138
    > (paresed with PHP5 DOM)


    xsl:sort needs to be a child of xsl:for-each or xsl:apply-templates.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Mar 24, 2005
    #2
    1. Advertising

  3. Your code imples that data is a sibling of field not a parent,
    is that right?

    <xsl:for-each select="field">
    <xsl:sort select="description[not(../data/@nosort='1']"/>

    would work although it's probably more efficient to move the test
    outside the xsl:choose, as that allows the processor to know that it
    doesn't need to sort anything in the unsorted case.

    <xsl:choose>
    <xsl:when test="data/@nosort='1'">
    <xsl:for-each select="field">
    <xsl:call-template name="x"/>
    </xsl:for-each>
    <xsl:eek:therwise>
    <xsl:for-each select="field">
    <xsl:sort select="description"/>
    <xsl:call-template name="x"/>
    </xsl:for-each>
    </xsl:eek:therwise>
    </xsl:choose>

    David
     
    David Carlisle, Mar 24, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jarle Presttun
    Replies:
    1
    Views:
    1,132
    Marrow
    Jul 9, 2003
  2. nobody
    Replies:
    0
    Views:
    539
    nobody
    Jun 1, 2004
  3. Replies:
    1
    Views:
    3,613
    A. Bolmarcich
    May 27, 2005
  4. Replies:
    2
    Views:
    9,279
    Martin Honnen
    Sep 5, 2006
  5. Navin
    Replies:
    1
    Views:
    704
    Ken Schaefer
    Sep 9, 2003
Loading...

Share This Page