xsl-list
[Top] [All Lists]

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

2010-06-29 13:42:30
On 29/06/2010 19:31, Ashton, Andrew wrote:
I am trying to look up a value in an XML document (people.xml) based
on a @ref attribute in my primary document (source.xml).  I know that
the @ref values in source.xml will match the @xml:id values in
people.xml.
the code posted appeared to use @xml:id in both documents rather than @ref ???




 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>

,

         <xsl:if test="$person/residence/country">
         <span about="ont:place#{$uriRef}" property="foaf:based_near">
             <xsl:value-of select="$person/residence/country"/>
         </span>
         </xsl:if>
</xsl:template>

But this is incredibly slow for large documents.  I have experimented
with using xsl:key, but I haven't had much.  Essentially I would like
to pre-populate the key with the values from people.xml, but I can't
quite figure out how to do that in a way that doesn't get me into a
looping scenario and/or that allows me to pass my $uriRef value to the
template that processes the key.  Can anyone explain a better
approach?

Thanks, 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>
--~--


________________________________________________________________________
This e-mail has been scanned for all viruses by Star.
________________________________________________________________________



--~------------------------------------------------------------------
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>