Back
Next
XSLT Combining is use to combine any other external
XSLT document. The <xsl:include> and <xsl:import> instructions give
us ways to incorporate XSLT style sheets programmatically.
There are two situations where this is useful.
Large and complex style sheets, like large complex other programs such as C++, are easier to maintain
when you break them into multiple documents with specific roles to play. In XSLT
combining, the <xsl:include> and <xsl:import> instructions let you assemble the pieces
in one master XSLT document. This modular advance
approach also makes it possible to share parts of a style sheet with other style sheets
that only want certain features
and not the whole thing; they can just include or import the parts they needed.
Customizing an existing style sheet without actually editing that style sheet is easy,
because we incorporate it, and then separately override any template rules that
don't do exactly what we want.
XSLT Tutorial section of <xsl:include> instruction is similar to the <xsl:include> instructions available in several
programming languages like Java. The XSLT processor replaces it with the contents of the style sheet
named in the href attribute. For example, the following
XSLT_Combining.xsl style sheet names the XSLT_Combining_with_XSL_Include.xsl style sheet to incorporate that style sheet:
Example of XSLT Combining
XML for XSLT Combining Example with <xsl:include> [XSLT_Combining.xml]
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="XSLT_Combining.xsl"?>
<employees>
<employee username="Emp1">
<employee_id>104</employee_id>
<employee_name>Smith</employee_name>
</employee>
<employee username="Emp2">
<employee_id>107</employee_id>
<employee_name>Mariya</employee_name>
</employee>
</employees>
XSLT for XSLT Combining Example [XSLT_Combining.xsl]
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="https://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="employees">
<html xmlns="https://www.w3.org/1999/xhtml">
<head> <title>XSLT Combining Example in XSLT Tutorial</title> </head>
<body>
<h1>
<a href="https://www.globalguideline.com/xslt/"><font color="0066CC">
Example of XSLT Combining at Global Guide Line XSLT Tutorial
</font></a>
</h1>
<h2>Employees at Global Guide Line</h2>
<ul>
<xsl:apply-templates select="employee">
<xsl:sort select="employee_name" />
</xsl:apply-templates>
</ul>
</body>
</html>
</xsl:template>
<xsl:include href="XSLT_Combining_with_XSL_Include.xsl"/>
</xsl:stylesheet>
XSLT Combining with <xsl:include> [XSLT_Combining_with_XSL_Include.xsl]
<xsl:stylesheet xmlns:xsl="https://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="employee">
<li>
<b><xsl:value-of select="employee_id"/></b>,
<i><xsl:value-of select="employee_name"/></i>
working at Global Guide Line.
</li>
</xsl:template>
</xsl:stylesheet>
Complete Example of XSLT Combining
View complete sources and outputs by simply clicking on file name of XSLT, XML
and Out Put of XSLT Combining Example.
Caution: Result may differ; in Microsoft internet explorer Netscape
navigator or Firefox may display with a little bit of difference.
Back
Next
|