Name
<xsl:macro>
Synopsis
<xsl:macro>...</xsl:macro>
Description
Creates a reusable XSL fragment thata 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.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access