<xsl:processing-instruction>  
出力ドキュメントで処理命令を作成します。
 
カテゴリ

命令

 
必須の属性
name
この処理命令の名前を定義します。

 
省略可能な属性

なし。

 
コンテンツ

XSLT テンプレート。テンプレートのコンテンツは、処理命令のデータになります。

 
指定先

<xsl:processing-instruction> テンプレート内に指定します。

 
定義先

XSLT 7.3 節「処理命令の作成」

 

処理命令を XML ドキュメントに追加するスタイルシートを次に示します。処理命令により、スタイルシート template.xsl がこの XML ドキュメントに関連付けられます。スタイルシートは次のとおりです。

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="xml"/>


  <xsl:template match="/">
    <xsl:processing-instruction name="xml-stylesheet">href="docbook/html/docbook.xsl" 
       type="text/xsl"</xsl:processing-instruction>
    <xsl:copy-of select="."/>
  </xsl:template>

</xsl:stylesheet>

このスタイルシートでは、<xsl:copy-of> 要素を使用して入力ドキュメントを結果ツリーにコピーし、処理命令を追加します。この XML ドキュメントに対してスタイルシートを使用します。

<?xml version="1.0"?>
<list>
  <title>A few of my favorite albums</title>
  <listitem>A Love Supreme</listitem>
  <listitem>Beat Crazy</listitem>
  <listitem>Here Come the Warm Jets</listitem>
  <listitem>Kind of Blue</listitem>
  <listitem>London Calling</listitem>
  <listitem>Remain in Light</listitem>
  <listitem>The Joshua Tree</listitem>
  <listitem>The Indestructible Beat of Soweto</listitem>
</list>

この変換を実行した場合の結果は次のとおりです。

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="docbook/html/docbook.xsl" type="text/xsl"?>
<list>
  <title>A few of my favorite albums</title>
  <listitem>A Love Supreme</listitem>
  <listitem>Beat Crazy</listitem>
  <listitem>Here Come the Warm Jets</listitem>
  <listitem>Kind of Blue</listitem>
  <listitem>London Calling</listitem>
  <listitem>Remain in Light</listitem>
  <listitem>The Joshua Tree</listitem>
  <listitem>The Indestructible Beat of Soweto</listitem>
</list>

処理命令のコンテンツはテキストです。生成された処理命令に 2 つの属性が含まれているように見えますが、処理命令をこのように作成することはできません。

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="xml"/>

  <xsl:template match="/">
    <xsl:processing-instruction name="xml-stylesheet">

      <!-- This doesn't work!  You can't put <xsl:attribute>
           elements inside a <xsl:processing-instruction> element. -->

      <xsl:attribute name="href">
        <xsl:text>docbook/html/docbook.xsl</xsl:text>
      </xsl:attribute>
      <xsl:attribute name="type">
        <xsl:text>text/xsl</xsl:text>
      </xsl:attribute>
    </xsl:processing-instruction>
    <xsl:copy-of select="."/>
  </xsl:template>

</xsl:stylesheet>

このスタイルシートを実行すると、XSLT プロセッサで例外が発生します。

?"/td>