【发布时间】:2015-05-31 15:39:54
【问题描述】:
我想将一个 XML 文档的内容包含到另一个 XML 文档中,并通过 xmlstarlet+XSLT 对其进行转换。我正在尝试使用 XInclude。 (我是 XInclude 和 XSLT 的新手。)不过,xmlstarlet 不会处理包含的 XML 文档,它只是让包含节点保持不变。
文件a.xml:
<?xml version="1.0" ?>
<doc xmlns:xi="http://www.w3.org/2001/XInclude">
a
<xi:include href="b.xml" />
b
</doc>
文件b.xml:
<?xml version="1.0" ?>
<snippet>
c
</snippet>
x.xsl“直通”模板:
<?xml version="1.0" encoding="windows-1250" ?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" />
<xsl:template match="/">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:transform>
要运行的命令行:
xmlstarlet tr x.xsl a.xml
预期的输出将类似于:
<?xml version="1.0" ?>
<doc xmlns:xi="http://www.w3.org/2001/XInclude">
a
<snippet>
c
</snippet>
b
</doc>
然而,我得到的结果是:
<?xml version="1.0"?>
<doc xmlns:xi="http://www.w3.org/2001/XInclude">
a
<xi:include href="b.xml"/>
b
</doc>
现在,我做错了什么?
【问题讨论】:
-
检查
xmlstarlet tr --help列出的选项 -
我做到了,而且确实找到了 --xinclude 参数。但正如我从MM的回答中看到的那样,我没有正确使用它。我为什么要写“--xinclude=b.xml”现在已经超出了我的理解。
标签: xslt xmlstarlet xinclude