Pages

Thursday, August 1, 2013

Use xsl:import to avoid rule collisions when sharing XSLT stylesheets

In an XSLT stylesheet, you can reference another XSLT stylesheet to access additional elements to your transformation. The syntax and mechanism of xsd:import is very similar to xsd:include:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl=http://www.w3.org/1999/XSL/Transform version="1.0">
<xsd:import href="morestuff.xsl">
...
</xsl:stylesheet>

The most important difference between xsd:import and xsd:include is that the primary stylesheet takes precedence over an imported stylesheet, whereas an included stylesheet is given equal precedence.

If there are no conflicting rules between stylesheets, xsl:include will do the job well. However, if there are overlapping rules, it will generate errors. Basically, you're including the entire stylesheet. With xsl:import, the primary stylesheet overrides any conflicting rules from the imported stylesheet. Instead of including the entire secondary stylesheet, you're importing only those rules that don't conflict with the primary XSLT.


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.