gpt4 book ai didi

xml - 如何在我的转换输出中打印 ' ' 的文字字符串

转载 作者:数据小太阳 更新时间:2023-10-29 02:34:24 25 4
gpt4 key购买 nike

我正在尝试使用 namespace 别名将 xsl 转换为 xsl 文档。我在输出中传递 ASCII 字符的文字值时遇到问题。

这是我在输入 xsl 中的行:

<xslAlt:variable name="result" select="translate({$var-name},'&#32;','&#160;')"/>

这是我得到的输出:

<xsl:variable name="result" select="translate(test-case-1-return,' ',' ')"/>

这是我梦寐以求的输出:

<xsl:variable name="result" select="translate(test-case-1-return,'&#32;','&#160;')"/>

换句话说,我不想在输出中扩展 ' ',' '。我想要它们在输入文档中的样子。

谢谢!

版本:我在此转换中使用的处理器是 Saxon (XSLT 2.0)

版本:我试过这个:

<xsl:character-map name="a">
<xsl:output-character character="&#32;" string="&#32;"/>
<xsl:output-character character="&#160;" string="&#160;"/>
</xsl:character-map>
<xsl:output indent="yes" use-character-maps="a"/>

<xslAlt:variable name="result" select="translate({$var-name}, '&#32;', '&#160;')"/>

但是也没用。我没有得到文字字符串 " 而是得到一个空格:

<xsl:variable name="result" select="translate(test-case-1-return,  ,  )"/>

结果。

我尝试使用另一个处理器 Xalan 1.0 进行转换。一切都如我所料。我不明白为什么它不适用于 Saxon。您会说:那您为什么不使用 Xalan 处理器呢?答案是:没有 xslt 2.0 支持,许多功能不适用于该处理器。

最佳答案

您是否使用 XSLT 2.0 处理器?在这种情况下,您可以使用字符映射,请参阅 http://www.w3.org/TR/xslt20/#character-maps语法和示例。

您将映射设置为

<xsl:character-map name="a">
<xsl:output-character character="&#32;" string="&amp;#32;"/>
<xsl:output-character character="&#160;" string="&amp;#160;"/>
</xsl:character-map>
<xsl:output indent="yes" use-character-maps="a"/>

一个简短的样本位于 http://xsltransform.net/6r5Gh2M .

关于xml - 如何在我的转换输出中打印 '&#32' 的文字字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33230917/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com