Re: [xsl] Getting Entity File Names

Subject: Re: [xsl] Getting Entity File Names
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 23 Oct 2003 16:44:00 +0100
I wrote

>   > The filename 
>   > of the fragment is the only identifier for over 
>   > 900 files.
>   The design of xml entities is that the physical distribution of the
>   document overfiles should not influence the logical document represented
>   by the xml markup. Xpath (and so xslt) strictly adheres to this
>   viewpoint and so the entities are fully expanded (leaving no record) as
>   the input tree is constructed.
>   You have two choices, edit your included documents so the top level
>   element has an id or edit your including document so that the reference
>   is marked, eg wrap each entity reference in an element.
>   <fileref id="myfile">&myfile;</fileref>
>   Which could be done using any regexp capable editor or perl or sed or
>   something like that.
>   David

Which isn't strictly true. There is record left of the extrenal entity
as the base uri of the node, which is used for resolving relative uri in
the document() function, but not otherwise available in xslt/xpath 1.

However it _is_ available in XPath2 so if you use saxon7 i think
(untested) you should be able to use base-uri() to access this.

In XSLT1 you can not access the uri (ie file name) but you can detect
that you are in an external entity as document('') pulls in a different
file in this case (assuming that the entity is well formed if read as a
document, which need not be the case.

In the following example there are three y elements and xslt reports
them as being in three different documents, as the generate-id are


<!ENTITY a SYSTEM "ena.xml">
<!ENTITY b SYSTEM "enb.xml">






<xsl:stylesheet xmlns:xsl="";

<xsl:template match="*">
:<xsl:for-each select="ancestor::*">:</xsl:for-each>
<xsl:value-of select="name()"/>
<xsl:text> - </xsl:text>
<xsl:value-of select="generate-id(document('',.))"/>


$ saxon en1.xml en1.xsl
<?xml version="1.0" encoding="utf-8"?>
:x - d1

::y - d2

::y - d3

::y - d1



This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:

 XSL-List info and archive:

Current Thread