如何从xml代码中删除货币欧元符号?下面我粘贴输出日期xml。
XML输入:
<products>
<product>
<sku>BTKUJ-1-2-2-3</sku>
<price>20€</price>
</product>
</products>
示例XSLT1.0:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:g="http://base.google.com/ns/1.0">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="products">
<xsl:element name="products">
<xsl:for-each select="product">
<xsl:element name="product">
<xsl:element name="sku">
AVM0TCPD_<xsl:value-of select="id"/>
</xsl:element>
<xsl:element name="priceimp">
<xsl:value-of select="price"/>
</xsl:element>-->
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
预期结果:
<products>
<product>
<sku>BTKUJ-1-2-2-3</sku>
**<price>20</price>**
</product>
</products>
我在您的尝试中找不到逻辑。如果你想做的只是从price
元素中删除欧元符号,你应该简单地做:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" 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:template match="price">
<xsl:copy>
<xsl:value-of select="translate(., '€', '')"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>