Child element to attribute
Sometimes, an input structure will include child elements to hold discrete parts of a compound value. Each part may need to be converted to an attribute in the output document. For example:
<image> <name>boat.gif</name> <y>60mm</y> <x>40mm</x> </image>
Again, patterns can be used to extract each part of the value into an attribute:
<xsl:template match="image"> <IMG SRC="{name}" HEIGHT="{y}" WIDTH="{x}" /> </xsl:template>
This is safe, because the string value of the named element is inserted, including the values of any sub-elements.
Get XSL companion, The now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.