Mark Brucks schrieb am 16.09.2009 um 09:22:41 (-0700):
> I would like to know which elements in a document exist as a result of
> XInclude processing and I need to retrieve the original <include>
> element so that I have access to the entire set of attributes.
> 
> My only solution, which I don't like, involves parsing the document
> twice. [...]

> Is there a better way?

If you process the document using XSLT 2.0 or XQuery, you can use the
XPath 2.0 base-uri() function to find out the base URI for the node.
This takes into account assemblage by external entities and XInclude.
See the following example.

G:\dev\XSLT2 :: type base-uri.xml
<!DOCTYPE BaseUriTest [
<!ENTITY bla SYSTEM "some.ent">
]>
<BaseUriTest>
        <Elm/>
        &bla;
        <Elm/>
        <AnotherElm/>
</BaseUriTest>

G:\dev\XSLT2 :: type some.ent
<Eins/>
<Zwei/>
<Drei/>

G:\dev\XSLT2 :: more /t2 base-uri.xsl
<xsl:stylesheet version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  <xsl:output method="text"/>
  <xsl:template match="*">
    <xsl:value-of select="concat( base-uri(), '&#9;', name(), '&#10;')"/>
    <xsl:apply-templates select="*"/>
  </xsl:template>
</xsl:stylesheet>

G:\dev\XSLT2 :: saxon9 base-uri.xml base-uri.xsl
file:/G:/dev/XSLT2/base-uri.xml BaseUriTest
file:/G:/dev/XSLT2/base-uri.xml Elm
file:/G:/dev/XSLT2/some.ent     Eins
file:/G:/dev/XSLT2/some.ent     Zwei
file:/G:/dev/XSLT2/some.ent     Drei
file:/G:/dev/XSLT2/base-uri.xml Elm
file:/G:/dev/XSLT2/base-uri.xml AnotherElm

-- 
Michael Ludwig

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscr...@xerces.apache.org
For additional commands, e-mail: j-users-h...@xerces.apache.org

Reply via email to