Hello folks, I am trying to set a fixed value to a tag in XML on comparing to a value in condition. such as
<xsl:when test="(//TestInput='XYZA') OR (//TestInput='XYZB') OR (//TestInput='XYZC') OR (//TestInput='XYZD')">abcd</xsl:when>
when i trying to run the transformation with an XML with tag <TestInput>
, it is giving me an error as
Extra illegal tokens: '(', '/', '/', 'TestInput', '=', ''XYZA'', ')', 'OR', '(', '/', '/', 'TestInput', '=', ''XYZB'', ')', 'OR', '(', '/', '/', 'TestInput', '=', ''XYZC'', ')', 'OR', '(', '/', '/', 'TestInput', '=', ''XYZD'', ')'
Please help me out in setting the value to this tag based on condition using OR operator in where clause.
Thanks in Advance
Case matters with XML/XSLT/XPath so use or
instead of OR
.
I created a test with the following XML:
<?xml version="1.0" encoding="utf-8"?>
<Test>
<Item>DAC</Item>
<Item>DAD</Item>
<Item>DAE</Item>
</Test>
And the following XSLT:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@* | node()">
<test>
<xsl:choose>
<xsl:when test="//Item[text()='DAC'] or //Item[text()='DAE']">
<output>Here is the text!</output>
</xsl:when>
<xsl:otherwise></xsl:otherwise>
</xsl:choose>
</test>
</xsl:template>
</xsl:stylesheet>
I get the following output:
<?xml version="1.0" encoding="utf-8"?>
<test>
<output>Here is the text!</output>
</test>
Tested with Micorosft.Net's XmlDocument class. The critical difference is the case of the 'or' statement.
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