【发布时间】:2016-09-28 06:58:41
【问题描述】:
我有一个遵循此方案的 XML 文件:
<translationData>
<product>
<attributeValue>
<value>1/4"</value>
<value1>1/4"</value1>
<currentValue>aaaa;bbbb</currentValue>
</attributeValue>
</product>
</translationData>
由于“currentValue”中的分号,我需要转义分号和“value”中的双引号。 我可以通过将所有文本放在 qoutes 中来转义分号,如下所示:
XSLT
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="utf-8" />
<xsl:param name="delim" select="';'" />
<xsl:param name="quote" select="'"'" />
<xsl:param name="break" select="'
'" />
<xsl:template match="/">
<xsl:apply-templates select="translationData/product/attributeValue" />
</xsl:template>
<xsl:template match="attributeValue">
<xsl:apply-templates />
<xsl:if test="following::*">
<xsl:value-of select="$break" />
</xsl:if>
</xsl:template>
<xsl:template match="*">
<!-- remove normalize-space() if you want keep white-space at it is -->
<xsl:value-of select="concat($quote, translate(.,'"','\"'), $quote)" />
<xsl:if test="following-sibling::*">
<xsl:value-of select="$delim" />
</xsl:if>
</xsl:template>
<xsl:template match="text()" />
</xsl:stylesheet>
但不知何故,输出是:
"1/4\";"1/4\";"aaaa;bbbb"
而不是
"1/4\"";"1/4\"";"aaaa;bbbb"
我哪里错了?
我是 XML 和 XSLT 的新手,在处理这个特定案例时没有发现任何问题。
XSLT 代码来自@Tomalak 对另一个问题的回答。见here
【问题讨论】:
-
R来自哪里? -
请不要在没有给予他人信任的情况下发布其他人的代码。您已经从stackoverflow.com/a/365372/18771 复制了这段XSLT。每当您使用不是您自己编写的代码时,请说出来。
-
@michael.hor257k 不应该在那里。刚刚删除它。
-
@Tomalak:抱歉不知道。再也不会发生!将立即对其进行编辑。