如果你想文本内容的价格与数量小于零,属于书与“NC”的名称元素。在这种情况下,您只需要进行以下模板匹配
<xsl:template match="Book[Name='NC']/Price[number(.) < 0]/text()">
然后您可以添加代码以将负值转化为正值。
尝试以下XSLT
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Book[Name='NC']/Price[number(.) < 0]/text()">
<xsl:value-of select="format-number(0 - number(.), '0.00')" />
</xsl:template>
</xsl:stylesheet>
当适用于您的XML,下面是输出
<Books>
<Book>
<Name>NC</Name>
<Price>100.50</Price>
</Book>
<Book>
<Name>B1</Name>
<Pr>450.60</Pr>
</Book>
<Book>
<Name>C1</Name>
<Price>35.20</Price>
</Book>
<Book>
<Name>D1</Name>
<P>5</P>
</Book>
</Books>
注意使用identity transform的复制现有元素。
请显示[你试过的东西](http://www.whathaveyoutried.com/) – Borodin 2013-04-23 11:22:54