Latest web development tutorials

XSLT <xsl: import> element

XSLT Elements Reference Manual Complete XSLT Element Reference Manual

Definition and Usage

<Xsl: import> element is the top element for the contents of a stylesheet into another stylesheet.

Note: The priority of the imported style sheets lower than export stylesheet.

Note: This element must be <xsl: stylesheet> or <xsl: transform> is the first child node.


grammar

<xsl:import href="URI"/>

Attributes

属性 描述
href URI 必需。规定要导入的样式表的 URI。

Example 1

Suppose you have a style sheet named "cdcatalog_ex3.xsl" of:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<tr>
<td><xsl:value-of select="catalog/cd/title"/></td>
<td><xsl:value-of select="catalog/cd/artist"/></td>
</tr>
</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>

The second, called "cdcatalog_import.xsl" stylesheet will import "cdcatalog_ex3.xsl":

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:import href="cdcatalog_ex3.xsl"/>

<xsl:template match="/">
<xsl:apply-imports/>
</xsl:template>

</xsl:stylesheet>

View the XML file , View the XSL file , view the results .

Note: This example can not be run in Netscape 6, Netscape 6 is not supported because the <xsl: apply-imports> element!


XSLT Elements Reference Manual Complete XSLT Element Reference Manual