XSLT Apply

创建于 2024-12-03 / 27
字体: [默认] [大] [更大]

<xsl:apply-templates> 元素将模板规则应用于当前元素或当前元素的子节点。


<xsl:apply-templates> 元素

<xsl:apply-templates> 元素将模板应用于当前元素或当前元素的子节点。

如果我们在<xsl:apply-templates>元素,它将只处理与属性值匹配的子元素。我们可以使用"select"属性来指定子节点的处理顺序。

查看以下XSL样式表:

实例

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

<xsl:template match="/">
  <html>
  <body>
  <h2>My CD Collection</h2>
  <xsl:apply-templates/>
  </body>
  </html>
</xsl:template>

<xsl:template match="cd">
  <p>
  <xsl:apply-templates select="title"/>
  <xsl:apply-templates select="artist"/>
  </p>
</xsl:template>

<xsl:template match="title">
  Title: <span style="color:#ff0000">
  <xsl:value-of select="."/></span>
  <br />
</xsl:template>

<xsl:template match="artist">
  Artist: <span style="color:#00ff00">
  <xsl:value-of select="."/></span>
  <br />
</xsl:template>

</xsl:stylesheet> 尝试一下 »

0 人点赞过