XSLT <xsl:import> 要素

定義と使用法

<xsl:import> 要素は、スタイルシートの内容を別のスタイルシートにインポートするためのトップレベル要素です。

注釈:インポートされたスタイルの優先順位はエクスポートされたスタイルシートより低いです。

注釈:この要素は <xsl:stylesheet> または <xsl:transform> の最初の子要素でなければなりません。

注釈:Netscape 6 はインポート優先規則をサポートしていないため、この要素の動作は <xsl:include> と同じです。

構文

<xsl:import href="URI"/>

属性

属性 説明
href URI 必須。インポートされるスタイルシートの URI を指定します。

例 1

仮に「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: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>

「cdcatalog_import.xsl」という名前の第2のスタイルシートは「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>

XML ファイルを確認XSL ファイルを確認結果を確認

注釈:この例は Netscape 6 で実行できません。なぜなら、Netscape 6 は <xsl:apply-imports> 要素をサポートしていないからです!