Today I Learned: The second argument to document() (XSLT 1.0)
When accessing documents with document()
I can provide a node set as second argument. If the
first argument is a relative URI reference, then the base URL of the first node of this node set is used to resolve
it. Otherwise the processor uses the stylesheet's base URL if the first argument is a string or the first argument's
base URL if it is a node.
In the diary of Augustus the Younger we annotate places and persons with a reference to a central registry file. The registry contains a link to an authority record and a standardized name of the entity.
<div xml:id="E1601-04-03">
<head>
<date when="1601-04-03">den 3 Aprilis <c>♀</c> </date>
</head>
<p>
H<ex>err</ex> <rs ref="register.xml#Julius_Ernst_Br-Db" type="person">Juli<ex>us</ex>
kommen</rs>; die Pfe<ex>rde</ex> nach <rs ref="register.xml#Warpke" type="place">warpke</rs>
geschickett.
</p>
</div>
And in the registry file:
<person xml:id="Julius_Ernst_Br-Db">
<idno type="URI">http://d-nb.info/gnd/121123553</idno>
<persName type="display">Julius Ernst, Braunschweig-Lüneburg, Herzog</persName>
</person>
I wanted the name to be displayed to the user once the mouse pointer hovers over the reference. I knew that I had to
dereference the value of the ref
attribute and put the display name in a HTML title
attribute. I did not know to which base URL relative URI
references are resolved: the stylesheet's, the documents', or maybe even the processor's current working directory.
Reading up on this in my trustworthy Kay Kay, Michael. XSLT: Programmer’s Reference. Birmingham: Wrox
Press, 2000 I got the whole story. If document()
is called with one
argument and the argument is a string, the stylesheet's base URL is used to resolve a relative URI
reference. If the argument is a node, the node's base URL is used. Use the second argument to provide a node whose
base URL should be used instead.
For me this meant: Simply use document(@ref)
without worries, since the relative URI reference
is resolved with the ref
attribute's base URI.