Name
<xsl:macro>
Synopsis
<xsl:macro>...</xsl:macro>
Description
Creates a reusable XSL fragment that can be inserted verbatim at
given points by invoking its macro name. A macro is defined using the
<xsl:macro>
element and can be inserted into an XSL
document using the <xsl:invoke>
element, as shown:
<xsl:macro name="warning-header"> <B>WARNING! </B> <xsl:contents/> </xsl:macro> <xsl:template match="warning"> <xsl:invoke macro="warning-header"> <xsl:apply-templates/> </xsl:invoke> </xsl:template>
This example places the HTML bold letters ”WARNING!“ in front of
any child elements of the <warning>
element in the target document.
When the macro is invoked, the contents of the <xsl:macro>
element
replace the <xsl:invoke>
element. In addition, the
<xsl:contents/>
element, seen in the macro itself, are replaced
with the contents of the <xsl:invoke>
element.
XSL macros are allowed to take arguments using the
<xsl:macro-arg>
element.
Get XML Pocket Reference 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.