我有以下xml,我想在Name元素值为“Total”时选择savings元素的值
请告诉我如何为这种特定情况编写xslt?
</ArrayOfCategoryData>
<CategoryData>
<Category>
<Category>
<Savingsdollar>0.00</Savingsdollar>
<Savingspercentage>0.00</Savingspercentage>
<Savingsusage>0.00</Savingsusage>
</Category>
</Category>
<Name>Refrigeration</Name>
</CategoryData>
<CategoryData>
<Category>
<Category>
<Savingsdollar>999.97</Savingsdollar>
<Savingspercentage>0.00</Savingspercentage>
<Savingsusage>9,998.04</Savingsusage>
</Category>
</Category>
<Name>Total</Name>
</CategoryData>
</ArrayOfCategoryData>
<table cellpadding='0' cellspacing='0'>
<tbody>
<tr>
<td style='border-left: none; border-bottom: none; width: 51px;'>
$ <xsl:value-of select="//ArrayOfCategoryData/CategoryData[Name='Total']//Savingsdollar/text()"/>
</td>
<td style='border-bottom: none; width: 29px;'>
<xsl:value-of select="//ArrayOfCategoryData/CategoryData[Name='Total']//Savingspercentage/text()"/>%
</td>
<td style='border-bottom: none;'>
<xsl:value-of select="//ArrayOfCategoryData/CategoryData[Name='Total']//Savingsusage/text()"/>
</td>
</tr>
</tbody>
</table>
答案 0 :(得分:1)
如果我申请
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="text()"/>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="CategoryData[Name='Total']">
<Total>
<xsl:value-of select="Category/Savings"/>
</Total>
</xsl:template>
到我的源XML:
<?xml version="1.0" encoding="UTF-8"?>
<Total>9,998.04</Total>
尝试使用我给你的XSLT; - )
BEst regarsd, 彼得