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

Subject: RE: [xsl] document() and key() boundaries.
From: "Kootstra, Anne" <anne.kootstra@xxxxxxxxxxxxx>
Date: Wed, 21 Mar 2007 20:41:01 +0100
Thanks Mike, comments are certainly appreciated. However, the problem is that
I can not predit the file name of the base.xml document. This, at least to me
seems like a prerequisite for the dummy for-each call. Right?

Just for my own understanding, which xslt 2.0 processors in an ASP or
standalone commandline are available?

Kind regards,

Anne

-----Oorspronkelijk bericht -----
Van: "Michael Kay" <mike@xxxxxxxxxxxx>
Aan: "xsl-list@xxxxxxxxxxxxxxxxxxxxxx" <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Verzonden: 21-3-07 18:18
Onderwerp: RE: [xsl] document() and key() boundaries.

In XSLT 2.0 the key() function has a third argument which you can set to the
root node of the document you want to search.

In 1.0 it always searches the document containing the context node so you
have to "cross the boundary" with a dummy call of xsl:for-each that changes
the context node:

<xsl:variable name="key-value" select="@theValue"/>
<xsl:for-each select="document('lookup.xml')">
   <xsl:apply-templates select="key('k', $key-value)"/>
</xsl:for-each>

Michael Kay
http://www.saxonica.com/



> -----Original Message-----
> From: anne.kootstra@xxxxxxxxxxxxx
> [mailto:anne.kootstra@xxxxxxxxxxxxx]
> Sent: 21 March 2007 15:28
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] document() and key() boundaries.
>
>
> 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.
>
> Base.xml
> ---------------------------------------------------
>
> <?xml version="1.0" encoding="ISO-8859-1"?> <?xml-stylesheet
> type="text/xsl" href="style.xsl" version="1.0"?>
>        <paragraphs>
>               <ContactRelationship>
>                      <FirstName>Bert</FirstName>
>                      <RelationshipType>Vader</RelationshipType>
>               </ContactRelationship>
>        </paragraphs>
> ----
>
> Detail.xml
> ---------------------------------------------------
> <?xml version="1.0" encoding="ISO-8859-1"?>
>
>        <paragraphs>
>
>               <paragraph>Parent name is: [<relation
> type="Father"/>] [This should be Bert]</paragraph>
>               <ContactRelationship>
>                      <FirstName>Klaas</FirstName>
>                      <RelationshipType>Father</RelationshipType>
>               </ContactRelationship>
>        </paragraphs>
>
> ----
>
> Style.xls
> ---------------------------------------------------
> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
>
> <xsl:key name="Test_A" match="ContactRelationship"
> use="RelationshipType" />
>
> <xsl:template match="/">
>        <xsl:call-template name="template"/> </xsl:template>
>
> <xsl:template match="paragraph">
>        <xsl:apply-templates />
> </xsl:template>
>
> <xsl:template match="relation">
>        <xsl:value-of select="key('Test_A',@type)/FirstName"/>
> </xsl:template>
>
> <xsl:template name="template">
>               <xsl:apply-templates
> select="document('detail.xml')/paragraphs/paragraph"/>
>
>               <xsl:for-each
> select="document('detail.xml')/paragraphs/paragraph">
>                      <xsl:apply-templates select="." />
>               </xsl:for-each>
> </xsl:template>
>
> </xsl:stylesheet>
>
> ----
>
> 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 MSXML.
>
> 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.



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