一段xml如下:
<bookstore bookid="2">
<book id="1">
<title>The Autobiography of Benjamin Franklin</title>
<price>8.99</price>
</book>
<book id="2">
<title>The Confidence Man</title>
<price>11.99</price>
</book>
</bookstore>现在我的xsl里需要根据bookstore 里的 bookid值来匹配出相应的那本book,我是这样写的
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="utf-8"/>
<xsl:template match="bookstore">
<books>
<xsl:if test="/bookstore[@bookid]">
<book>
<xsl:value-of select="@bookid" />---
<xsl:value-of select="/bookstore/book[@id='2']/title"/>
</book>
</xsl:if>
</books>
</xsl:template>
</xsl:stylesheet>大家注意看一下
<xsl:value-of select="/bookstore/book[@id='2']/title"/>这里的ID我现在是写死的,我希望能用bookstore里的bookid的属性值代替这个值,但是发现不能这样写,请问这种情况我该如何处理?
<bookstore bookid="2">
<book id="1">
<title>The Autobiography of Benjamin Franklin</title>
<price>8.99</price>
</book>
<book id="2">
<title>The Confidence Man</title>
<price>11.99</price>
</book>
</bookstore>现在我的xsl里需要根据bookstore 里的 bookid值来匹配出相应的那本book,我是这样写的
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="utf-8"/>
<xsl:template match="bookstore">
<books>
<xsl:if test="/bookstore[@bookid]">
<book>
<xsl:value-of select="@bookid" />---
<xsl:value-of select="/bookstore/book[@id='2']/title"/>
</book>
</xsl:if>
</books>
</xsl:template>
</xsl:stylesheet>大家注意看一下
<xsl:value-of select="/bookstore/book[@id='2']/title"/>这里的ID我现在是写死的,我希望能用bookstore里的bookid的属性值代替这个值,但是发现不能这样写,请问这种情况我该如何处理?
<xsl:value-of select="/bookstore/book[@id=$bookid]/title"/>