You can specify an XPath expression in the test
attribute, without resorting to an additional variable and its text node child :
<xsl:when test="education_level="Bachelor's Degree/Undergraduate Degree"">
Here is the complete conversion:
<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="/*"> <xsl:choose> <xsl:when test="education_level="Bachelor's Degree/Undergraduate Degree""> <opleiding> <xsl:attribute name="id"> <xsl:value-of select="'30001'"/> </xsl:attribute> <xsl:value-of select="'Specialisation'"/> </opleiding> </xsl:when> </xsl:choose> </xsl:template> </xsl:stylesheet>
when this conversion is applied to the following XML document :
<t> <education_level>Bachelor Degree/Undergraduate Degree</education_level> </t>
required, the correct result is obtained :
<opleiding id="30001">Specialisation</opleiding>
Additional note : you do not need DOE, and in this particular case it will either be ignored or cause an error - this is because DOE is allowed only by instructions that create the node text - not an attribute.
source share