有关XML & XSL (我使用SharePoint 2007)XML/XSL:如何比较两个节点并根据比较结果设置另一个节点的值?
你如何比较两个节点的一个问题?
在下面的例子中,我想比较'promotionprice'和'price'。
如果'promotionprice'等于或大于'price',那么'OK'应该是'NO'。 如果'promotionprice'小于'price',那么'OK'应该是'YES'。
我不确定我是否使用了正确的语法,因为在sharepoint中它不起作用,它总是给出YES。
XML example:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<promotionprice>15.00</promotionprice>
<year>1985</year>
<OK>Yes</OK>
</cd>
<cd>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price>
<promotionprice>5.00</promotionprice>
<year>1988</year>
<OK>Yes</OK>
</cd>
</catalog>
XSL example:
...
<!-- title node -->
<td>
<xsl:value-of select="@title"/>
</td>
<!-- artist node -->
<td>
<xsl:value-of select="@artist"/>
</td>
...
<!-- OK node -->
<td>
<xsl:choose>
<xsl:when test="promotionprice >= price">
<xsl:value-of select="'NO'"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'YES'"/>
</xsl:otherwise>
</xsl:choose>
</td>
WANTED RESULT:
<table border="1">
<tr>
<td>Empire Burlesque</td>
<td>Bob Dylan</td>
<td>USA</td>
<td>Columbia</td>
<td>10.90</td>
<td>15.00</td>
<td>1985</td>
<td>NO</td>
</tr>
<tr>
<td>Hide your heart</td>
<td>Bonnie Tyler</td>
<td>UK</td>
<td>CBS Records</td>
<td>9.90</td>
<td>5.00</td>
<td>1988</td>
<td>YES</td>
</tr>
</table>
非常感谢!
请编辑问题并提供转换的确切结果。 –