LISTSERV mailing list manager LISTSERV 15.5

Help for XML-L Archives


XML-L Archives

XML-L Archives


View:

Next Message | Previous Message
Next in Topic | Previous in Topic
Next by Same Author | Previous by Same Author
Chronologically | Most Recent First
Proportional Font | Monospaced Font

Options:

Join or Leave XML-L
Reply | Post New Message
Search Archives


Subject: Re: AND or OR in XSLT
From: "John E. Simpson" <[log in to unmask]>
Reply-To:[log in to unmask]
Date:Tue, 3 Apr 2001 09:05:03 -0400
Content-Type:text/plain
Parts/Attachments:
Parts/Attachments

text/plain (54 lines)


Sprinna wrote:

> Following is to set attribute as yellow if severity<3
>         <TR>
>           <xsl:for-each select="severity">
>             <xsl:if expr="(this.nodeTypedValue &lt; 3)">
>               <xsl:attribute name="class">yellow</xsl:attribute>
>             </xsl:if>
>           </xsl:for-each>
> But how to do if I want to severity<3, and finished="N"

I don't know what flavor of XSLT you're using. In XSLT 1.0, the xsl:if
element has a test attribute, but not an expr attribute.

Under XSLT 1.0, you'd construct the xsl:if like this:

     <xsl:if test="severity &lt; 3 and finished='N'">

If this "if-test" is to be merged with the one you quoted in full,
above, you might want to put them both inside an xsl:choose block like this:

     <xsl:choose>
          <xsl:when test="this.nodeTypedValue &lt; 3">
               <xsl:attribute name="class">yellow</xsl:attribute>
          </xsl:when>
          <xsl:when test="severity &lt; 3 and finished='N'">
               <xsl:attribute name="class">gold</xsl:attribute>
          </xsl:when>
          <!-- ...as many xsl:when's as you need :)... -->
          <!-- xsl:otherwise is optional, provides fallback -->
          <xsl:otherwise>
               <xsl:attribute name="class">silver</xsl:attribute>
          </xsl:otherwise>
     </xsl:choose>

The xsl:when's are mutually exclusive: The first xsl:when for which the
value of the test attribute is true is the "winner," thus the order in
which you place them within the xsl:choose is significant. Leaving them
as separate xsl:if's allows for the possibility that more than one might
be true, with perhaps unexpected results.

First thing I'd straighten out, though, is the XSLT processor question.
If you're still using the MSXML processor which was built into Internet
Explorer 5.0 and earlier, you should know that it implements a 2- or
3-year out-of-date version of the XSLT spec. No one -- not even
Microsoft -- recommends its continued use. There's an XSLT 1.0-compliant
version of MSXML available from the Microsoft Web site; the best source
of information about this is Joshua Allen's Unofficial MSXML XSLT FAQ, at:
     http://www.netcrucible.com/xslt/msxml-faq.htm

================================================================
John E. Simpson          | "When I was a little kid we had a sand
http://www.flixml.org    | box. It was a quicksand box. I was an
XML Q&A: www.xml.com     | only child... eventually." (Steven Wright)

Back to: Top of Message | Previous Page | Main XML-L Page

Permalink



LISTSERV.HEANET.IE

CataList Email List Search Powered by the LISTSERV Email List Manager