【发布时间】:2021-12-31 14:02:21
【问题描述】:
如何从 xml 代码中删除货币欧元符号?下面我粘贴输出日期xml。
XML 输入:
<products>
<product>
<sku>BTKUJ-1-2-2-3</sku>
<price>20€</price>
</product>
</products>
XSLT 1.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元素,为什么你的代码使用<xsl:element name="priceimp">?使用translate与例如translate(., '€', '')从值中删除符号。