我正在使用XSLT将我的所有Decimal类型节点格式化为XML格式的欧洲格式。 我的XML看起来像是
<?xml version="1.0" encoding="utf-16"?>
<Envelope>
<Body>
<getPriceRecommendationResponse>
<status>
<statusCode>Success</statusCode>
</status>
<priceRecommendation>
<tssArticleNumber>Item Number</tssArticleNumber>
<compoundCode>T46N</compoundCode>
<compoundGroupCodeBucket>A</compoundGroupCodeBucket>
<compoundCodeBucket>T46 & others</compoundCodeBucket>
<qualityIndexCode>-</qualityIndexCode>
<qualityIndexBucket>Std Quality</qualityIndexBucket>
<weight>66.0341</weight>
<weightGroupBucket>BT 36.2227 and 73.4214</weightGroupBucket>
<weightIsValidBucket>YES</weightIsValidBucket>
<subGroupCode>PT</subGroupCode>
<subGroupCodeBucket>7:B03</subGroupCodeBucket>
<stockDistinction>MTS</stockDistinction>
<productIdBucket>Item</productIdBucket>
<referencePrice>41.9176</referencePrice>
<averageQuantity>5</averageQuantity>
<quantityAdjustments>0.77</quantityAdjustments>
<highDV>2.05792</highDV>
<averageDV>1.40269</averageDV>
<lowDV>0.95137</lowDV>
<additionalAdjustmentsTotal>1</additionalAdjustmentsTotal>
<highPrice>66.42256189184</highPrice>
<averagePrice>45.27399672488</averagePrice>
<lowPrice>30.70694327624</lowPrice>
</priceRecommendation>
</getPriceRecommendationResponse>
</Body>
</Envelope>
我的XSLT如下所示
<?xml-stylesheet type="text/xsl" href="decimalformat.xsl"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:msxml="urn:schemas-microsoft-com:xslt">
<xsl:output method="xml" omit-xml-declaration="yes" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<!-- identity transform -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:decimal-format name="eu" decimal-separator=',' grouping-separator='.' />
<xsl:template match="*[number()=number()]">
<xsl:copy>
<xsl:value-of select="format-number(@*|node(), '#.##0,##########', 'eu')" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
但是我在我的应用程序中尝试这个时遇到错误,而它在转换工具中运行良好。错误如下。
Microsoft Dynamics NAV
对System.Xml.Xsl.XslTransform.Load的调用因此消息失败:表达式必须求值为节点集。
行
如果我排除代码
<xsl:value-of select="format-number(@*|node(), '#.##0,##########', 'eu')" />
它没有给出错误但没有用。 我把它改成了
<xsl:value-of select="format-number(., '#.##0,##########', 'eu')" />
也是但同样的错误。请帮我。感谢
谢谢Martin Honnen,我试过你建议的代码,仍然有同样的错误。我看过一个类似的帖子,它提供了有关我得到的错误的更多信息。 http://mikeschinkel.com/blog/gettingpastthexslterrorexpressionmustevaluatetoanodeset/#comment-484235 我认为问题是博客中提到的点
**However, if you select from a node-set but instead use </xsl:value-of> as a subelement, you get a string, and you can’t later select directly from a string.**
答案 0 :(得分:0)
我已经尝试了http://xsltransform.net/eiZQaF6并且工作正常,样式表是
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:msxml="urn:schemas-microsoft-com:xslt">
<xsl:output method="xml" omit-xml-declaration="yes" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<!-- identity transform -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:decimal-format name="eu" decimal-separator=',' grouping-separator='.' />
<xsl:template match="*[not(*) and number()=number()]">
<xsl:copy>
<xsl:value-of select="format-number(., '#.##0,##########', 'eu')" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
结果是
<Envelope>
<Body>
<getPriceRecommendationResponse>
<status>
<statusCode>Success</statusCode>
</status>
<priceRecommendation>
<tssArticleNumber>Item Number</tssArticleNumber>
<compoundCode>T46N</compoundCode>
<compoundGroupCodeBucket>A</compoundGroupCodeBucket>
<compoundCodeBucket>T46 & others</compoundCodeBucket>
<qualityIndexCode>-</qualityIndexCode>
<qualityIndexBucket>Std Quality</qualityIndexBucket>
<weight>66,0341</weight>
<weightGroupBucket>BT 36.2227 and 73.4214</weightGroupBucket>
<weightIsValidBucket>YES</weightIsValidBucket>
<subGroupCode>PT</subGroupCode>
<subGroupCodeBucket>7:B03</subGroupCodeBucket>
<stockDistinction>MTS</stockDistinction>
<productIdBucket>Item</productIdBucket>
<referencePrice>41,9176</referencePrice>
<averageQuantity>5</averageQuantity>
<quantityAdjustments>0,77</quantityAdjustments>
<highDV>2,05792</highDV>
<averageDV>1,40269</averageDV>
<lowDV>0,95137</lowDV>
<additionalAdjustmentsTotal>1</additionalAdjustmentsTotal>
<highPrice>66,4225618918</highPrice>
<averagePrice>45,2739967249</averagePrice>
<lowPrice>30,7069432762</lowPrice>
</priceRecommendation>
</getPriceRecommendationResponse>
</Body>
</Envelope>
关于XSLT的唯一奇怪的事情是领先的<?xml-stylesheet type="text/xsl" href="decimalformat.xsl"?>
,如果你想使用客户端XSLT,它通常属于XML。