gpt4 book ai didi

xml - xslt fn :replace not working as expected

转载 作者:行者123 更新时间:2023-12-04 06:23:36 25 4
gpt4 key购买 nike

我正在尝试替换字符串 locationtocation所以基本上这是我的代码:

<div id="{fn:replace('location','l','t')}">

但不是给我 tocation它给了我 t ?!

现场示例:转至 http://www.w3schools.com/xsl/tryxslt.asp?xmlfile=cdcatalog&xsltfile=cdcatalog_ex1
在第二个 textarea 中输入此代码并点击按钮 Edit and Click Me :
<?xml version="2.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<div>
<xsl:value-of select="fn:replace('location','l','t')"/>
</div>
</xsl:template>
</xsl:stylesheet>

最佳答案

我无法重现报告的问题 .

当我使用 Saxon 9.1.05 和 XQSharp 执行此转换时:

<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output omit-xml-declaration="yes" indent="yes"/>

<xsl:template match="/">
<div id="{replace('location','l','t')}"/>
</xsl:template>
</xsl:stylesheet>

在任何 XML 文档(未使用)上,两种情况下的结果都是预期的,正确的 :
<div xmlns:xs="http://www.w3.org/2001/XMLSchema" id="tocation"/>

这意味着您使用的是不兼容/有缺陷的 XSLT 2.0 处理器 .

联系供应商并提交错误。

如果您使用的是 XSLT 1.0 处理器 ,您将需要编写一个递归命名模板来执行简单的通用替换(不使用 RegEx)。在“xslt”标签中有很多很好的例子,可以在类似问题的答案中找到。

但是,您想要执行的特定更改可以更轻松地完成 :
<div id="{translate('location','l','t')}"/>

关于xml - xslt fn :replace not working as expected,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6287865/

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