簡體   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?

我有這些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

除非您關閉該功能,否則所有XInclude處理器都應使用包含文件的URL添加一個@xml:base屬性。 因此,您無需執行任何操作,它應該已經是:

<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。)

我99%確信一旦處理了xi:include,您將擁有一個文檔(和單個信息集),該文檔將無法確定文檔中給定部分的URL。

我認為您需要將這些信息直接放置在包含的各個文件中。 話雖如此,您仍然可以嘗試document-uri ,但是我認為所有節點都將返回相同的URI。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM