xml - xslt 转换错误:XTSE0010:元素 xsl:mode 不得直接出现在 xsl:stylesheet 中
问题描述
我正在寻找将节点从一个值更改为另一个值。不是节点的值,而是节点的名称。不是标签内的内容。
维基百科会说“标签”为:
标签 标签是一个以 < 开头并以 > 结尾的标记结构。标签有三种风格:
start-tag, such as <section>; end-tag, such as </section>; empty-element tag, such as <line-break />.
因此,我希望将一个名称的所有上述标签重命名为另一个名称。至于或等foo
_ _bar
bar
baz
运行saxonb-xslt
返回:
Saxon 9.1.0.8J from Saxonica
也许这个版本Saxon
没有能力,或者更有可能的xslt
是,有缺陷。
xml
从较大的文件中 截断:
<csv>
<foo>
<entry>Reported_Date</entry>
<entry>HA</entry>
<entry>Sex</entry>
<entry>Age_Group</entry>
<entry>Classification_Reported</entry>
</foo>
<bar>
<entry>2020-01-26</entry>
<entry>Vancouver Coastal</entry>
<entry>M</entry>
<entry>40-49</entry>
<entry>Lab-diagnosed</entry>
</bar>
<record>
<baz>2020-02-02</baz>
<entry>Vancouver Coastal</entry>
<entry>baz</entry>
<entry>50-59</entry>
<entry>Lab-diagnosed</entry>
</record>
<record>
<entry>2020-02-05</entry>
<entry>Vancouver Coastal</entry>
<entry>F</entry>
<entry>20-29</entry>
<entry>Lab-diagnosed</entry>
</record>
</csv>
xslt
文件 :
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:output indent="yes"/>
<xsl:mode on-no-match="shallow-copy"/>
<xsl:template match="foo">
<baz><xsl:apply-templates/></baz>
</xsl:template>
</xsl:stylesheet>
错误:
Error at xsl:mode on line 9 column 41 of bc.rename.xslt:
XTSE0010: Element xsl:mode must not appear directly within xsl:stylesheet
Error at xsl:mode on line 9 column 41 of bc.rename.xslt:
XTSE0010: Unknown XSLT element: mode
Failed to compile stylesheet. 2 errors detected.
xml
文档和xslt
文档都通过xmllint
且没有错误。
解决方案
xsl:mode
需要 XSLT 3.0。AFAIK,Saxon 9.1 仅支持 XSLT 2.0。
改为尝试:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<!-- identity transform -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="foo">
<baz>
<xsl:apply-templates/>
</baz>
</xsl:template>
</xsl:stylesheet>
推荐阅读
- google-cloud-platform - 如何将 Google Cloud VM 实例的外部 IP 更改为我的“正常”IP
- snapshot - 我应该在创建快照后创建新流吗?
- r - 运行一个函数并将其计算值和输入值存储在新数据框中
- javascript - 在 setTimeout() 内触发异步操作,当应用程序从 dom 卸载时不起作用
- python - AttributeError:无法获取属性“DeprecationDict”
AttributeError:无法获取属性“DeprecationDict”
pickle.load(打开(模型,'rb'))
pickle.load(打开(模型,'rb'))
body_f
- nginx - body_filter_by_lua_block 代码将 URL 替换为所有 Mime 类型的另一个 URL
- python - 如何修复:冻结和无值
- javascript - 如何在 Ionicframework 中输出异步/可观察数据?
- c# - 从 GPRS C# 获取当前时间日期
- maven - maven-jar-plugin/maven-war-plugin 的 ${scmBranch} 和 $\{scmBranch} 之间的区别