Reputation: 27357
I have these XML files:
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.
In the XSLT transformation, I 'd want to add the name of the file the <section>
element came from, so I get something like:
<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
?
Upvotes: 1
Views: 224
Reputation: 2167
Unless you turn off that feature, all XInclude processors should add an @xml:base attribute with the URL of the included file. 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. )
Upvotes: 1
Reputation: 9873
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.
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.
Upvotes: 0