【问题标题】:In XSLT, how do I get the filepath of the xml file of a certain element if that xml file was included with xinclude?在 XSLT 中,如果某个元素的 xml 文件包含在 xinclude 中,我如何获取该 xml 文件的文件路径?
【发布时间】:2012-05-16 14:12:02
【问题描述】:

我有这些 XML 文件:

master.xml (which uses XInclude to include child1.xml and child2.xml)
child1.xml
child2.xml

child1.xmlchild2.xml 都包含带有一些文本的 <section> 元素。

在 XSLT 转换中,我想添加 <section> 元素来自的文件的名称,所以我得到如下内容:

<section srcFile="child1.xml">Text from child 1.</section>
<section srcFile="child2.xml">Text from child 2.</section>

如何检索值child1.xmlchild2.xml

【问题讨论】:

    标签: java xslt docbook xinclude


    【解决方案1】:

    除非您关闭该功能,否则所有 XInclude 处理器都应添加 @xml:base 属性 包含文件的 URL。所以你不必做任何事情,它应该已经是:

    <section xml:base="child1.xml">Text from child 1.</section>
    <section xml:base="child2.xml">Text from child 2.</section>
    

    (如果需要,可以使用 XSLT 将@xml:base attr 转换为@srcFile。)

    【讨论】:

      【解决方案2】:

      我有 99% 的把握,一旦 xi:include 被处理,您将拥有一个文档(和单个信息集),它不会让您确定文档的任何给定部分来自哪个 URL。

      我认为您需要将该信息直接放在各个包含的文件中。话虽如此,您仍然可以尝试document-uri,但我认为所有节点都会返回相同的URI。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-04-03
        • 1970-01-01
        • 2010-10-13
        相关资源
        最近更新 更多