Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

'OR' 'AND' Operands

Status
Not open for further replies.

MaKSiNG

Technical User
Dec 4, 2003
19
Hi All,

Can someone tell me how to do an <xsl:when> statement testing for one condition 'OR' another, as well as one condition 'AND' another?

This is the gist of it but it obviously does not work:
Code:
<xsl:choose>
<xsl:when test="record/item/value='Text1' OR 'Text2' AND record/item/value/item/value='Text3' ">
<xsl:call-template name="MyTemplate1"></xsl:call-template>
</xsl:when>
</xsl:choose>

I want the template to be called if the first node contains Text1 or Text2 but the second node must also contain Text3.



Thx,
MaKS
 
It needs to be in the form

test="value='Text1' or value='Text2' and value='Text3'"
 
Thanks fpmurphy,

That works a treat!


I have another quick one.

I need to do something like:
test=("value!='Text1' or value!='Text2') and value='Text3'"

So the test checks that a certain value node does not contain either 'Text1' or 'Text2' but a separate value node must contain 'Text3'.


Thx,
MaKS
 
Can anybody see why:

Code:
<xsl:when test="record/item/value='Backbone HR New Join Form' or record/item/value='New Position ' and record/item/value/item[value='ALL_Flexible_Form']">

works, but:

Code:
<xsl:when test="record/item/value!='Backbone HR New Join Form' or record/item/value!='New Position ' and record/item/value/item[value='ALL_Flexible_Form']">

doesn't?

I have tried parenthesis around the 2 elements of the 'OR' statement as well.

Thx,
MaKS

Thx,
MaKS
 
Looking at your xpath-expressions, it seems that the node 'record/item/value' contains text AND a childnode 'item'.
If you nest nodes that way, the value of the node is its own value + the value of the childnode(s).
Another pitfall is the use of the operator '!=': if there is no node, (node != something) always is false.

For examples: parse this:
Code:
<root>
   <level1 descr="X, properly nested sub">
      <value>X</value>
      <level2>Y</level2>
   </level1>

   <level1 descr="not X, properly nested sub">
      <value>Y</value>
      <level2>Y</level2>
   </level1>

   <level1 descr="X, not properly nested sub">
      <value>X 
      <level2>Y</level2>
      </value>
   </level1>

   <level1 descr="not X, not properly nested sub">
      <value>Y 
      <level2>Y</level2>
      </value>
   </level1>

   <level1 descr="no value-node">X</level1>
</root>
Code:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
   <xsl:output method="html" />
   <xsl:template match="/root">
      <html>
         <table border="1">
            <tr>
               <td>description</td>
               <td>value</td>
               <td>value = 'X'</td>
               <td>contains(value , 'X')</td>
               <td>not (value = 'X')</td>
               <td>value != 'X'</td>
               <td>not contains(value , 'X'))</td>
            </tr>
            <xsl:for-each select="level1">
               <tr>
                  <td><xsl:value-of select="@descr" /></td>
                  <td><xsl:value-of select="value" /></td>
                  <td><xsl:if test="value = 'X'">V</xsl:if></td>
                  <td><xsl:if test="contains(value , 'X')">V</xsl:if></td>
                  <td><xsl:if test="not (value = 'X')">V</xsl:if></td>
                  <td><xsl:if test="value != 'X'">V</xsl:if></td>
                  <td><xsl:if test="not (contains(value , 'X'))">V</xsl:if></td>
               </tr>
            </xsl:for-each>
         </table>
      </html>
   </xsl:template>
</xsl:stylesheet>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top