xsl-list
[Top] [All Lists]

Re: [xsl] Trouble understanding the Test expression in xsl:if

2009-05-27 19:56:43
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/

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

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