XSLT <xsl: apply-templates> element
Definition and Usage
<Xsl: apply-templates> element child node can apply a template to the current element or to the current element.
If we are to: add select attribute <xsl apply-templates> element, then it will only deal with the matching sub-element value of the property. We can use the select attribute to specify the order to deal with the child node.
grammar
<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>
Attributes
属性 | 值 | 描述 |
---|---|---|
select | expression | 可选。规定要处理的节点。星号选取整个节点集。如果省略该属性,则将选取当前节点的所有子节点。 |
mode | name | 可选。如果存在为相同元素定义的多个处理方法,那么用 mode 可以区分它们。 |
Example 1
H1 elements in the document enclosed with each title element:
<?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>
Example 2
H1 elements in the document enclosed with all sub-elements belonging to the message of the title element:
<?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>
Example 3
Surrounded by the h1 element in the document mode attribute is set to "big" the message to all child nodes:
<?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>
Complete XSLT Element Reference Manual