how to test if my condition is this;
<xsl:if test="node = '1' or node='2'">
<input name="list_{@id}" value="{@id}" type="checkbox"/>
</xsl:if>
Is IF statement allowed OR condition? Please advice..
If I want to test one condition (a simple if ), I use <xsl:if> . If I want to change that to test more than one condition or add an else case, I have to use <xsl:choose> , <xsl:when> , and <xsl:otherwise> .
XSLT <xsl:if> The <xsl:if> element contains a template that will be applied only if a specified condition is true. Tip: Use <xsl:choose> in conjunction with <xsl:when> and <xsl:otherwise> to express multiple conditional tests!
The XSLT <xsl:if> element is used to specify a conditional test against the content of the XML file.
Almost all programming languages have conditional branching structures. XSL has two: <xsl:if> and <xsl:choose>. XPath also has the if-then-else structure.
Is IF statement allowed OR condition?
No, but XPath has an or
operator -- do note that XPath is case-sensitive language.
The XPath expression in the provided code:
node = '1' or node='2'
is syntactically correct.
or
is a standard XPath operator and can be used to combine two subexpressions.
[33] OperatorName ::= 'and' | 'or' | 'mod' | 'div'
Here is a complete XSLT transformation 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 transformation is applied on 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 wanted, correct result is produced (all elements copied with the exception of <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>
You can use or just like you did in your example. Here are the supported operators in XSLT.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With