我如何使用XSLT检索元素的最后一个子节点,例如:
<zoo>
<example>
<name>A</name>
</example>
<example>
<name>B</name>
</example>
<example>
<name>C</name>
</example>
<example>
<name>D</name>
</example>
</zoo>
Run Code Online (Sandbox Code Playgroud)
我怎样才能找回D?谢谢你的帮助
使用如下表达式:
/*/example[last()]/name
Run Code Online (Sandbox Code Playgroud)
要么:
/*/example[last()]/name/text()
Run Code Online (Sandbox Code Playgroud)
以下样式表只是输出D(依赖于文本节点的内置模板):
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes"/>
<xsl:template match="/">
<xsl:apply-templates select="/*/example[last()]/name"/>
</xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3930 次 |
| 最近记录: |