www.webdeveloper.com
Results 1 to 4 of 4

Thread: XSLT: How to use xsl:sort and xsl:choose simultaneously

  1. #1
    Join Date
    Dec 2008
    Posts
    6

    XSLT: How to use xsl:sort and xsl:choose simultaneously

    Hello friends,

    I have a newbie question.

    How to use xsl:sort and xsl:choose simultaneously on a single stylesheet.

    Code:
    <xsl:for-each select = "CATALOG/CD">
                            <xsl:sort select = "TITLE" />
    			<xsl:choose>
    			
    
    			<xsl:when test="PRICE &gt; 10">	
    			
    					
    				<tr bgcolor = "#ececec">
    			
            			<td ><xsl:value-of select="TITLE" /></td>
            			<td><xsl:value-of select="ARTIST" /></td>
    					<td><xsl:value-of select="COUNTRY" /></td>
          			</tr>
    		
    			</xsl:when>
    			
    			<xsl:otherwise>
    				
    				<tr bgcolor = "#ababab">
    			
            			<td ><xsl:value-of select="TITLE" /></td>
            			<td><xsl:value-of select="ARTIST" /></td>
    					<td><xsl:value-of select="COUNTRY" /></td>
          			</tr>
    				
    				</xsl:otherwise>	
    			
    			</xsl:choose>
    		</xsl:for-each>
    The above code will not work in Firefox.
    The error returned was
    Error loading stylesheet: Parsing an XSLT stylesheet failed.

    Please give your advice.

  2. #2
    Join Date
    Feb 2009
    Posts
    33
    Well it is hard to determine without seeing your full XSLT and your input XML. Other than that the code looks ok except it is a bit verbose. You should be using something like this:

    Code:
    <tr>
    					<xsl:attribute name="bgcolor">
    						<xsl:choose>
    							<xsl:when test="PRICE &gt; 10">#ececec</xsl:when>
    							<xsl:otherwise>#ababab</xsl:otherwise>
    						</xsl:choose>
    					</xsl:attribute>
    					<td ><xsl:value-of select="TITLE" /></td>
    					<td><xsl:value-of select="ARTIST" /></td>
    					<td><xsl:value-of select="COUNTRY" /></td>
    				</tr>

  3. #3
    Join Date
    Dec 2008
    Posts
    6
    Well it is hard to determine without seeing your full XSLT and your input XML.
    Here is the XML file.
    http://w3schools.com/xsl/cdcatalog.xml

  4. #4
    Join Date
    May 2007
    Posts
    288
    We still need your full xsl, as that seems to be where the problem is (according to the error message)
    Also, "CATALOG/CD"
    will match nothing, as xml is case sensitive. Similarly for all your value-of elements.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles