在test中,如何判断节点属性的值是否等于某个字符?
peppi 2002-10-06 04:47:11 有一XML:
<top>
<table>
<tr name="date">
<ITEM>
<text>654</text>
</ITEM>
</tr>
</table>
<table>
<tr name="logo">
<logo>
agd
</logo>
</tr>
</table>
</top>
我想根据<tr>的属性的不同值,做不同的XSLT处理
我的XSL:
<xsl:template match="top">
<body>
<xsl:choose>
<xsl:when test="string(table/tr/@name) = logo">
<xsl:apply-templates select="table" mode="logo"/>
</xsl:when>
<xsl:when test="string(table/tr/@name) = date">
<xsl:apply-templates select="table" mode="date"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="table" mode="others"/>
</xsl:otherwise>
</xsl:choose>
</body>
</xsl:template>
<xsl:template match="table" mode="logo">
<table width="97%" border="0" align="center" cellspacing="0"> <xsl:apply-templates select="tr" mode="logo"/>
</table>
</xsl:template>
<xsl:template match="table" mode="date">
<table width="100%" border="0" align="center" cellspacing="0">
<xsl:apply-templates select="tr" mode="date"/>
</table>
</xsl:template>
有错误,我估计问题在<xsl:when test="string(table/tr/@name) = logo">,test中该怎么判断某个节点的属性值是什么呢?我把string()去掉也不行,我换成table/tr/@name/text()也不行,换成test="table/tr[@name=logo]"也是不行,各位,我有两个要求:
一:给个正确答案
二:告诉我为什么以上那几个不行,问题在哪?帮我解解疑
谢谢!!!