Reputation: 11771
I want to import a XSLT stylesheet, but essentially to have it ignored by default, and only use its templates when called upon.
Our content contains custom XML + DocBook-style tables, so it's currently transformed by two XSLTs: XML => my.xsl => docbook.xsl => XHTML. Is it possible to do this all from my.xsl?
<!-- My XML -->
<xsl:template match="a"/>
<xsl:template match="b"/>
<xsl:template match="c"/>
<!-- DocBook XML -->
<xsl:template match="table">
<xsl:apply-templates select="." mode="docbook"/>
</xsl:template>
The problem with importing the docbook.xsl stylesheet is that it includes many other templates that interfere with existing templates. Ideally, there would be a way to import docbook.xsl into a specified mode, but that's not possible. Is there a way to do this without modifying docbook.xsl?
Upvotes: 0
Views: 199
Reputation: 243529
Use modes.
In the imported stylesheet have all templates be in a mode with unique name that nobody uses. For example use prefix:mymode
and have the prefix prefix
bound to a namespace that belongs to you.
To invoke processing from the imported stylesheet, use:
<xsl:apply-templates select="$vNodesToBeProcessed" mode="prefix:mymode"/>
Upvotes: 1
Reputation: 12729
Templates in the main stylesheet always have higher priority than templates from imported stylesheets. To avoid invoking the imported templates, simply override them in the main, in the required circumstances.
This should be the preferred technique. An alternative is:
Upvotes: 2