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

Multiple ifs (Was: RE: Simplified production for FilterExpr

Subject: Multiple ifs (Was: RE: Simplified production for FilterExpr in XPath spec?)
From: Jeni Tennison <Jeni.Tennison@xxxxxxxxxxxxxxxx>
Date: Tue, 18 Jul 2000 11:25:42 +0100
multiple ifs
Jukka,

>But that "sem[@role='user']" doesnt work, am I away from right answer ??

There are two problems with your XSLT template.

The first lies in the XPaths that you're using.  Your xsl:ifs appear within
a template that matches a 'sem' element.  Within the template, the 'sem'
element is the current node.  The XPaths in the xsl:if tests are of the
form sem[@role='user'], which looks for a 'sem' element child of the
current node with a 'role' attribute with a value of 'user'.  You're
actually interested in the @role attribute of the current node, the 'sem'
element, rather than any 'sem' child, so you should try using the XPath
"@role='user'" and "@role='error'" instead.

The second lies in the use of multiple xsl:if elements within the
xsl:attribute.  Whenever an xsl:if tests true, then the contents of that
xsl:if is processed.  This means that, given <sem role="error" />, the XSLT
processor evaluates:

 - @role='user' = false
 - @role='error' = true
 - @role = true

As both @role='error' and @role are true, you get an output of:

  <sem type="parameterdoesnt work" />

which isn't what you wanted.

Instead, use the xsl:choose element with xsl:when:

<xsl:template match="sem"> 
  <sem>
    <xsl:attribute name="type">
      <xsl:choose>
        <xsl:when test="@role='user'">state</xsl:when>     
        <xsl:when test="@role='error'">parameter</xsl:when>
        <xsl:when test="@role">doesnt work</xsl:when>
      </xsl:choose> 	
    </xsl:attribute>
    <xsl:apply-templates/>	
  </sem>
</xsl:template>

or, possibly:

<xsl:template match="sem"> 
  <sem>
    <xsl:attribute name="type">
      <xsl:choose>
        <xsl:when test="@role='user'">state</xsl:when>     
        <xsl:when test="@role='error'">parameter</xsl:when>
        <xsl:otherwise>doesnt work</xsl:otherwise>
      </xsl:choose> 	
    </xsl:attribute>
    <xsl:apply-templates/>	
  </sem>
</xsl:template>

This is tested and works with SAXON.

I hope that helps,

Jeni

Dr Jeni Tennison
Epistemics Ltd, Strelley Hall, Nottingham, NG8 6PE
Telephone 0115 9061301 ? Fax 0115 9061304 ? Email
jeni.tennison@xxxxxxxxxxxxxxxx



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.