Reputation: 27
I'm trying to compare an elements value with a string, but the if condition doesn't work. If the value of Hello is World, I want to get the value of Status. So the output should be ABCDEFG.
XML:
<?xml version="1.0" encoding="UTF-8"?>
<DATA xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Hello>World</Hello>
<Company>
<Id>12345</Id>
<Name>Name</Name>
<Status>ABCDEFG</Status>
</Company>
</DATA>
XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.0">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
<Account>
<xsl:if test="Hello = World">
<xsl:value-of select="DATA/Company/Status" />
</xsl:if>
</Account>
</xsl:template>
</xsl:stylesheet>
Upvotes: 0
Views: 1040
Reputation: 116992
Try it this way:
<xsl:template match="/DATA">
<Account>
<xsl:if test="Hello = 'World'">
<xsl:value-of select="Company/Status" />
</xsl:if>
</Account>
</xsl:template>
Upvotes: 1