Set output attributes with XSLT

Setting attributes in output elements generated by XSLT transform is extremely easy: just enclose the XPath expression in curly brackets within the quotes surrounding the attribute value. You might even concatenate multiple XPath expressions or XPath expressions and string constants within the attribute value. For example, if you want to set CLASS attribute of the output DIV element to the value of the input @id attribute prefixed by "CSS-", use the following syntax:
<DIV class="CSS-{@id}">
However, if you want to eliminate the attributes that would have empty values (for example, the DIV element in the previous example should not have the class attribute if the @id input attribute does not exist), use xsl:attribute in combination with xsl:if or xsl:choose.

No comments:

Post a Comment