<xsl:apply-templates>  
適切なテンプレートをノードセットに適用するように XSLT プロセッサに指示します。
 
カテゴリ

命令

 
必須の属性

なし。

 
省略可能な属性
select
テンプレートの適用先となるノードを選択する XPath 式が含まれます。有効な値には、ノードセット全体を選択する * が含まれます。この属性がない場合、現在のノードのすべての子要素が選択されます。

mode
特定の目的のためのテンプレートを記述できるようにする便利な構文である、処理モードを定義します。たとえば、 mode= " toc " を指定して < xsl:template > を記述し、ドキュメントの目次用のノードを処理したり、 mode= " print " mode= " online " mode= " index " などを指定して他の < xsl:template > を記述し、同じ情報を別の目的で処理できます。

 
コンテンツ

<xsl:apply-templates> 要素は、任意の数の <xsl:sort> および <xsl:with-param> 要素を含むことができます。ほとんどの場合、<xsl:apply-templates> は空です。

 
指定先

<xsl:apply-templates> はテンプレート内に指定します。

 
定義先

XSLT 5.4 節「Applying Template Rules」

 

ケーススタディ (第 9 章 を参照) では、同じデータからいくつかの異なる出力を作成する必要がありました。これには、<xsl:apply-templates> 要素の mode 属性を使用して対応しました。メインテンプレート (match="/") を次に示します。

<xsl:template match="/">
  <xsl:apply-templates select="tutorial" mode="build-main-index"/>
  <redirect:write select="concat($curDir, $fileSep, 'index.html')"> 
    <xsl:apply-templates select="tutorial" mode="build-main-index"/>
  </redirect:write>
  <xsl:apply-templates select="tutorial" mode="build-section-indexes"/>
  <xsl:apply-templates select="tutorial" mode="build-individual-panels"/>
  <xsl:apply-templates select="tutorial" mode="generate-graphics"/>
  <xsl:apply-templates select="tutorial" mode="generate-pdf-file">
    <xsl:with-param name="page-size" select="'ltr'"/>
  </xsl:apply-templates>

  <xsl:apply-templates select="tutorial" mode="generate-pdf-file">
    <xsl:with-param name="page-size" select="'a4'"/>
  </xsl:apply-templates>
  <xsl:apply-templates select="tutorial" mode="generate-zip-file"/>
</xsl:template>

この例では、<tutorial> 要素を 8 回選択していますが、毎回別のモード (または同じモードに対して異なるパラメータ) でテンプレートを適用します。