Is there’s a way to print the variable in the element as an attribute?
sample xml:
<list>
<name>John Doe</name>
<name>Paul Niel</name>
<name>Luke Dee</name>
</list>
Here’s my sample xslt;
<xsl:variable name="isDisabled">
<xsl:if test="name='John Doe'">
<xsl:attribute name="disabled">disabled</xsl:attribute>
</xsl:if>
</xsl:variable>
and I want to print the isDisabled varible like this;
<input id="textName" name="name" type="text" {$isDisabled} />
output;
<input id="textName" name="name" type="text" disabled="disabled" />
You don’t need any variable to accomplish this task.
When this transformation is applied on the provided XML document:
the wanted, correct result is produced:
Explanation:
Proper use of templates and template pattern matching.
Note: If you have a case (not this one) where it is really necessary to use a variable to create an attribute, this can be done in the following way:
Explanation:
Proper use of AVT (Attribute Value Templates)