I have an XML document as follows
<Element>
<Element1>
<Element2 attr1="Horizontal"/>
</Element1>
<Element1 attr1="V"/>
<Element1>
<Element2 attr1="Island"/>
</Element1>
</Element>
I would like to have an XSLT to transform the XML with the following conditions:
- If the attr1 value is "Horizontal" or "H", it has to be replaced with "H"
- If the attr1 value is "Vertical" or "V", it has to be replaced with "V"
- If the attr1 value is "Island" or "ISL", it has to be replaced with "ISL"
- Otherwise the same value in attr1 appears as it is
So that the resultant XML appears as follows:
<Element>
<Element1>
<Element2 attr1="H"/>
</Element1>
<Element1 attr1="V"/>
<Element1>
<Element2 attr1="ISL"/>
</Element1>
</Element>
I have the following XSLT. The or condition does not seem to work here. How can I change it?
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@attr1">
<xsl:attribute name="attr1">
<xsl:choose>
<xsl:when test=". ='Horizontal' or 'H'">
<xsl:text>H</xsl:text>
</xsl:when>
<xsl:when test=". = 'Vertical' or 'V'">
<xsl:text>V</xsl:text>
</xsl:when>
</xsl:choose>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
test="boolean(.='Horizontal') or boolean('H')", andboolean('H')is always true, so the test always passes.