?
Solved

XSLT conditional sort

Posted on 2005-05-13
5
Medium Priority
?
855 Views
Last Modified: 2013-11-18
I need to do a conditional sort, but XSLT says, "xsl:sort is not allowed in this position...".
Any help much appreciated. Error-causing code is below:

<xsl:for-each select="form/div[@class='carhire']">
      <xsl:if test="$standard = 'yes' and $nonfloridafree = 'no'">
            <xsl:sort select="var[@name='price']"/>
      </xsl:if>
      <xsl:if test="$floridafree = 'yes' or $nonfloridafree = 'yes'">
            <xsl:sort select="../var[@name='price']"/>
      </xsl:if>
... etc ...

Many thanks,
Mab
 
0
Comment
Question by:mjacobs2929
  • 3
  • 2
5 Comments
 

Author Comment

by:mjacobs2929
ID: 13996226
PS... the following gives the same error:

          <xsl:for-each select="form/div[@class='carhire']">
      <xsl:choose>
            <xsl:when test="$standard = 'yes'">
            <xsl:sort select="var[@name='price']"/>
            </xsl:when>
            <xsl:otherwise>
            <xsl:sort select="../var[@name='price']"/>
            </xsl:otherwise>
      </xsl:choose>


Many thanks,
Mab
0
 
LVL 6

Expert Comment

by:metalmickey
ID: 13996503
should the sort function must be the first child of a for-each or an apply-templates?

MM
0
 

Author Comment

by:mjacobs2929
ID: 13996606
The file is not applying templates in this section, if this is what you mean.
0
 
LVL 6

Accepted Solution

by:
metalmickey earned 2000 total points
ID: 13996713
        <xsl:for-each select="form/div[@class='carhire']">
         <xsl:sort select="var[@name='price']"/>
         </xsl:for-each>


Must be the first child...i think

could you not declare a global variable and do the test in there?


 <xsl:sort select="$Myvar"/>
0
 

Author Comment

by:mjacobs2929
ID: 13996896
That does it! Thank you.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question