xsl-list
[Top] [All Lists]

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

2010-06-30 08:33:01
On Tue, Jun 29, 2010 at 2:42 PM, David Carlisle 
<davidc(_at_)nag(_dot_)co(_dot_)uk> 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::*[(_at_)xml:id]/@xml:id)[last()]"/>
        </xsl:variable>

probably better to write that as

 <xsl:variable name="uriRef" select="ancestor::*[(_at_)xml:id][1]/@xml:id"/.

        <xsl:variable name="person"

select="document('file:///people.xml')//person[(_at_)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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>