简体   繁体   English

在XSLT中,如果某个XML文件包含在xinclude中,我如何获取该元素的xml文件的文件路径?

[英]In XSLT, how do I get the filepath of the xml file of a certain element if that xml file was included with xinclude?

I have these XML files: 我有这些XML文件:

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

Both child1.xml and child2.xml contain a <section> element with some text. child1.xmlchild2.xml都包含带有某些文本的<section>元素。

In the XSLT transformation, I 'd want to add the name of the file the <section> element came from, so I get something like: 在XSLT转换中,我想添加<section>元素来自的文件的名称,因此我得到如下信息:

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

How do I retrieve the values child1.xml and child2.xml ? 如何获取值child1.xmlchild2.xml

Unless you turn off that feature, all XInclude processors should add an @xml:base attribute with the URL of the included file. 除非您关闭该功能,否则所有XInclude处理器都应使用包含文件的URL添加一个@xml:base属性。 So you don't have to do anything, it should already be: 因此,您无需执行任何操作,它应该已经是:

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

( If you want, you can use XSLT to transform the @xml:base attr into @srcFile. ) (如果需要,可以使用XSLT将@xml:base attr转换为@srcFile。)

I'm 99% sure that once xi:include has been processed, you have a single document (and single infoset) that won't let you determine which URL any given part of the document came from. 我99%确信一旦处理了xi:include,您将拥有一个文档(和单个信息集),该文档将无法确定文档中给定部分的URL。

I think you will need to place that information directly in the individual included files. 我认为您需要将这些信息直接放置在包含的各个文件中。 Having said that, you can still give document-uri a try, but I think all nodes will return the same URI. 话虽如此,您仍然可以尝试document-uri ,但是我认为所有节点都将返回相同的URI。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM