The xsl:apply-imports element is used to apply (invoke) the definitions and template rules of an imported stylesheet that normally might be overridden by the importing stylesheet.
When one or more stylesheets are imported using the xsl:import element, the imported stylesheets are assigned a lower import precedence than the importing stylesheet. This means that the definitions and rules contained in the imports may be overridden and therefore may not be applied. The purpose of the xsl:apply-imports element is to permit these overridden rules to be applied when and where you desire them to be applied.
This element has no attributes.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:import href="xslt_example_choose.xsl" />
<xsl:template match="/">
<html>
<body>
<xsl:apply-imports />
</body>
</html>
</xsl:template>
</xsl:stylesheet>
NAME: Bugs Bunny AGE: 31
NAME: Daisy Duck AGE: 51
NAME: Minnie Mouse AGE: 24
NAME: Pluto AGE: 21
NAME: Porky Pig AGE: 44
NAME: Road Runner AGE: 48
This is the code for xslt_example_applyimports.xsl.
We use the DevGuru Staff List XML file for our example with the following header:
<?xml-stylesheet type="text/xsl" href="xslt_example_applyimports.xsl"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<xsl:for-each select="devguru_staff/programmer">
<xsl:choose>
<xsl:when test="age < 30">
<span style="color:red;">
NAME: <xsl:value-of select="name" /> AGE: <xsl:value-of select="age" />
</span>
</xsl:when>
<xsl:when test="age < 40">
<span style="color:orange;">
NAME: <xsl:value-of select="name" /> AGE: <xsl:value-of select="age" />
</span>
</xsl:when>
<xsl:when test="age < 50">
<span style="color:green;">
NAME: <xsl:value-of select="name" /> AGE: <xsl:value-of select="age" />
</span>
</xsl:when>
<xsl:when test="age < 60">
<span style="color:blue;">
NAME: <xsl:value-of select="name" /> AGE: <xsl:value-of select="age" />
</span>
</xsl:when>
<xsl:otherwise>
<span style="color:black;">
NAME: <xsl:value-of select="name" /> AGE: <xsl:value-of select="age" />
</span>
</xsl:otherwise>
</xsl:choose>
<br />
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
The code for xslt_example_choose.xsl