xml - XSLT 打开其他 xml 文件

标签 xml xslt xslt-1.0

我要合并 XML 文件(并添加元信息),其相对路径在我的输入 XML 文件中指定。我要合并的文件位于名为"file"的子目录中 输入文件的结构如下

<files>
   <file>
       <path>files/firstfile.xml</path>
   </file>
   <file>
       <path>files/secondfile.xml</path>
   </file>
</files>

firstfile.xml 和 secondfile.xml 的结构如下

    <tables>
        <table name = "...">
        ...
        </table>
        ...
    <tables>

我想将一个文件的所有表节点放在一个组中,并向其中添加元信息。所以我编写了以下 XSLT 样式表:

   <xsl:template match="/">
    <tables>
          <xsl:apply-templates/>
    </tables>
</xsl:template>


<xsl:template name = "enrichWithMetaInformation" match = "file">
            <xsl:apply-templates select="document(./path)/tables">
                <xsl:with-param name="file" select="."/>
            </xsl:apply-templates>


</xsl:template>

<xsl:template match="tables">

    <group>
        <meta>
            ...Some meta data ...
        </meta>
        <xsl:copy-of select="./table"/>
    </group>
</xsl:template>

对于每个文件我都会得到一个错误:

The system could not find the file specified.

它表示已返回一个空节点集(因此无法加载文件)。有人知道如何解决这个问题吗?

干杯

最佳答案

检查源文档的基本 URI 是否已知,例如通过执行 base-uri(/)。在参数作为节点(或节点集)提供的情况下,此值用于解析传递给 document() 的相对 URI。

基本 URI 未知的两种常见情况是:

(a) 如果您将源文档作为内存中的 DOM 提供

(b) 如果您将源文档作为输入流或没有已知 URI 的阅读器提供。

关于xml - XSLT 打开其他 xml 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18469398/

相关文章:

html - 元 : HTML in the style of JSON

java - 如何使用java创建xml?

xslt - 如何在 XSLT 中插入

xml - 使用 xslt 向使用 xml 创建的 excel 文件添加样式

xml - 多个元素到平面字符串转换

c# - 将 Storyboards 制作成 WPF 中多个控件可以使用的资源

xml - Coldfusion - XML 格式化从 API 调用返回的字符串

html - 在 XSLT 中使用列表元素

css - 将样式应用于 xml 属性值

xml - 将每个单词的第一个字符转换为大写