Is an IF statement to allow an OR condition in XSLT?

how to check if my condition is this;

<xsl:if test="node = '1' or node='2'"> <input name="list_{@id}" value="{@id}" type="checkbox"/> </xsl:if> 

Is an IF statement or condition permitted? Please advice.

+7
source share
2 answers

Is an IF statement or condition permitted?

No, but XPath has an or operator - note that XPath is case sensitive.

XPath expression in the provided code :

 node = '1' or node='2' 

is syntactically correct .

or is the standard XPath operator and can be used to combine two subexpressions .

[33] OperatorName :: = 'and' | 'or' | 'mod' | 'Div'

Here is a complete XSLT conversion example:

 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output omit-xml-declaration="yes" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> <xsl:template match="num[ . = 3 or . = 5]"/> </xsl:stylesheet> 

When this conversion is applied to the following XML document :

 <nums> <num>01</num> <num>02</num> <num>03</num> <num>04</num> <num>05</num> <num>06</num> <num>07</num> <num>08</num> <num>09</num> <num>10</num> </nums> 

the desired, correct result is created (all elements are copied except for <num>03</num> and <num>05</num> :

 <nums> <num>01</num> <num>02</num> <num>04</num> <num>06</num> <num>07</num> <num>08</num> <num>09</num> <num>10</num> </nums> 
+6
source

You can use either in the same way as in your example. Operators in XSLT are supported here .

+1
source

All Articles