[xsl] document() and key() boundaries.

Subject: [xsl] document() and key() boundaries.
From: <anne.kootstra@xxxxxxxxxxxxx>
Date: Wed, 21 Mar 2007 16:27:57 +0100
Dear experts.

The application I'm working on is one to generate a letter from two xml
files utilising xslt. The base.xml file contains all the information
about the person who the letter is intended for. In the detail.xml
standard text fragments are stored that make up the letter. The xslt
file processes the tags in the base.xml file and grabs the relevant text
fragments from the detail.xml file using the document() function.

The problem I'm facing is that some of the text fragments in the
detail.xml file have a reference to fields in the base.xml document.
However, I've been unable to cross the boundary from detail.xml back
into the base.xml using the key() function. In the included example
there is a text fragment that requires the inclusion of the first name
of the father. The end result is that the name "Klaas" is included,
however I intended to include the name "Bert". The only reason the
father's details are also present in the detail.xml is to prove the fact
that the technique works, but that it searches the wrong document. In
real live this information would not be present in detail.xml.


<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="style.xsl" version="1.0"?>

<?xml version="1.0" encoding="ISO-8859-1"?>


              <paragraph>Parent name is: [<relation type="Father"/>]
[This should be Bert]</paragraph>


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xsl:stylesheet version="1.0"

<xsl:key name="Test_A" match="ContactRelationship"
use="RelationshipType" />

<xsl:template match="/">
       <xsl:call-template name="template"/>

<xsl:template match="paragraph">
       <xsl:apply-templates />

<xsl:template match="relation">
       <xsl:value-of select="key('Test_A',@type)/FirstName"/>

<xsl:template name="template">

                     <xsl:apply-templates select="." />



In the included example I have used two scenarios I've tested and
re-tested. There is one additional thing worth mentioning: the file name
of the base.xml is variable. It is therefore not possible to create a
direct document() link between the detail.xml and the base.xml.
Hopefully someone can help me with this particular situation. It appears
that the focus is locked to the detail.xml document and that is why
"Klaas" is included. Anyone having any suggestions on how to include the
name "Bert"?

The intended version of XSLT is 1.0 however, if 2.0 might be the working
solution I would be curios to know that too. The processor for the job
is at this point msxsl.exe. Which I believe is based upon version 4.0 of

Any and all suggestions are appreciated.

Kind regards,

Anne Kootstra

This message is for the designated recipient only and may contain privileged,
proprietary, or otherwise private information.  If you have received it in
error, please notify the sender immediately and delete the original.  Any
other use of the email by you is prohibited.

Current Thread