XSLT <xsl:apply-templates>の要素
定義と使用法
<xsl:apply-templates>の要素の子ノードは、現在の要素に、または現在の要素にテンプレートを適用することができます。
私たちがしている場合:select属性ます。<xsl適用-テンプレート>要素を追加し、それが唯一のプロパティの一致するサブ要素値を扱います。 私たちは、子ノードに対応するために指定するには、select属性を使用することができます。
文法
<xsl:apply-templates select="expression" mode="name">
<!-- Content:(xsl:sort|xsl:with-param)* -->
</xsl:apply-templates>
<!-- Content:(xsl:sort|xsl:with-param)* -->
</xsl:apply-templates>
プロパティ
属性 | 值 | 描述 |
---|---|---|
select | expression | 可选。规定要处理的节点。星号选取整个节点集。如果省略该属性,则将选取当前节点的所有子节点。 |
mode | name | 可选。如果存在为相同元素定义的多个处理方法,那么用 mode 可以区分它们。 |
例1
各タイトル要素で囲まれた文書に記載されているH1要素:
<?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="title">
<h1><xsl:apply-templates/></h1>
</xsl:template>
</xsl:stylesheet>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="title">
<h1><xsl:apply-templates/></h1>
</xsl:template>
</xsl:stylesheet>
例2
title要素のメッセージに属するすべてのサブ要素で囲まれた文書に記載されているH1要素:
<?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="message">
<h1><xsl:apply-templates select="title"/></h1>
</xsl:template>
</xsl:stylesheet>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="message">
<h1><xsl:apply-templates select="title"/></h1>
</xsl:template>
</xsl:stylesheet>
例3
文書モード属性はすべての子ノードへのメッセージ "ビッグ"に設定されている中で、H1要素に囲まれました:
<?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="message">
<h1><xsl:apply-templates select="*" mode="big"/></h1>
</xsl:template>
</xsl:stylesheet>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="message">
<h1><xsl:apply-templates select="*" mode="big"/></h1>
</xsl:template>
</xsl:stylesheet>
完全なXSLT要素のリファレンス・マニュアル