请问关于xslt的查找节点有关问题
请教关于xslt的查找节点问题.
XML数据如下:
<book>
<author> 张三 </author>
<buyer> Tom </buyer>
</book>
<book>
<author> 李四 </author>
<buyer> Jack </buyer>
</book>
-----------------------
已知人名 "张三 ",但不知道他是author还是buyer。请问如何查找到该结点,并取得节点名“author”。
注:不能使用if语句判断。
------解决方案--------------------
<?xml version= '1.0 ' encoding= 'gb2312 '?>
<xsl:stylesheet xmlns:xsl= "http://www.w3.org/TR/WD-xsl ">
<xsl:template match= "/ ">
<xsl:apply-templates select= "//book[author = '张三 '] "/>
<xsl:apply-templates select= "//book[buyer = '张三 '] "/>
</xsl:template>
<xsl:template match= "//book[author = '张三 '] ">
author: <xsl:value-of select= "author "/> <br/>
</xsl:template>
<xsl:template match= "//book[buyer = '张三 '] ">
buyer: <xsl:value-of select= "buyer "/> <br/>
</xsl:template>
</xsl:stylesheet>
XML数据如下:
<book>
<author> 张三 </author>
<buyer> Tom </buyer>
</book>
<book>
<author> 李四 </author>
<buyer> Jack </buyer>
</book>
-----------------------
已知人名 "张三 ",但不知道他是author还是buyer。请问如何查找到该结点,并取得节点名“author”。
注:不能使用if语句判断。
------解决方案--------------------
<?xml version= '1.0 ' encoding= 'gb2312 '?>
<xsl:stylesheet xmlns:xsl= "http://www.w3.org/TR/WD-xsl ">
<xsl:template match= "/ ">
<xsl:apply-templates select= "//book[author = '张三 '] "/>
<xsl:apply-templates select= "//book[buyer = '张三 '] "/>
</xsl:template>
<xsl:template match= "//book[author = '张三 '] ">
author: <xsl:value-of select= "author "/> <br/>
</xsl:template>
<xsl:template match= "//book[buyer = '张三 '] ">
buyer: <xsl:value-of select= "buyer "/> <br/>
</xsl:template>
</xsl:stylesheet>