[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Trouble understanding the Test expression in xsl:i

Subject: Re: Trouble understanding the Test expression in xsl:if
From: Liam Quin <liam@xxxxxx>
Date: Wed, 27 May 2009 19:56:18 -0400
Re:  Trouble understanding the Test expression in xsl:i
On Wed, May 27, 2009 at 02:28:05PM -0500, Keith Gilbert wrote:
> My shortened XML data:
> <category>
> 	<category_name>apples</category_name>
> 	<product>red delicious</product>
> </category>
> 	<category_name>oranges</category_name>
> 	<product>sunkist</product>
> </category>

> My simplified XSLT:
> 
> <xsl:template match="category">
> 	<xsl:apply=templates/>
> </xsl:template>
> 
> <xsl:template match="category_name">
> 	<xsl:if test="category_name = apples">
> 		<xsl:call-template name=apple_template/>
> 	</xsl:if>
> </xsl:template>

I think you'd do better by saying what you're trying to do here.

(1) you want the aples category to use a different template:
<xsl:template match="category[category_name = 'apples'">
  something different
</xsl:template>

(2) you want to do something additional to the category name
when there are apples

<xsl:template match="category_name">
  <xsl:if test=". = 'apples'">
    <!--* call a template to display the category name: *-->
    <xsl:call-template name="apple-template" />
  </xsl:if>
</xsl:template>

Your "if" doesn't work because it's inside a template that is matching
the category_name element, and it's looking for a category_name element
inside that, whereas in fact there's just a string.
Most likely you want my suggestion (1), to treat the whole category
element differently if its name is "apples".

Liam

-- 
Liam Quin, W3C XML Activity Lead, http://www.w3.org/People/Quin/
http://www.holoweb.net/~liam/ * http://www.fromoldbooks.org/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.