Re: [xsl] Populating keys with values from other documents

Subject: Re: [xsl] Populating keys with values from other documents
From: "Ashton, Andrew" <andrew_ashton@xxxxxxxxx>
Date: Wed, 30 Jun 2010 09:32:13 -0400
On Tue, Jun 29, 2010 at 2:42 PM, David Carlisle <davidc@xxxxxxxxx> wrote:
> the code posted appeared to use @xml:id in both documents rather than @ref
> ???

Yes, sorry, I mistyped that.

>  I can do something like this:
>>
>> <xsl:template match="name">
>>         <xsl:variable name="uriRef">
>>             <xsl:value-of
>> select="(ancestor::*[@xml:id]/@xml:id)[last()]"/>
>>         </xsl:variable>
>
> probably better to write that as
>
>  <xsl:variable name="uriRef" select="ancestor::*[@xml:id][1]/@xml:id"/.
>
>>         <xsl:variable name="person"
>>
>> select="document('file:///people.xml')//person[@xml:id=concat($var,
>> '')]"/>
>
> in xslt2 you can write that as
>  <xsl:variable name="person"
>              select="key('p',$var,document('file:///people.xml'))"/>
>
> where key is defined by
>
> <xsl:key name="p" match="person" use="@xml:id"/>
>
> If you are using xslt1, you need to wrap the whole of this part of the code
> in
> <sl;for-each select="document('file:///people.xml')">
>
> ...
>
>  <xsl:variable name="person"
>              select="key('p',$var)"/>
> ...
>
> </xsl:for-each>

This was just what I needed, thank you very much.  I am using xslt1
for compatibility.

For comparison, the original method (i.e. making separate document()
calls for each value) took about 35 seconds to render in my webapp.
This method takes about 1 second.

Regards,

Andy

Current Thread