Re: [xsl] variable question

Subject: Re: [xsl] variable question
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Wed, 10 Nov 2004 22:00:19 +0000
Hi Bruce,

I haven't been following this thread, just saw my name mentioned...

Wendell said:
>> Maybe Mike or Jeni or someone can suggest an easier way to do this in
>> XSLT 2.0.

There isn't any way of dynamically evaluating strings as XPaths in
XSLT 2.0 -- you still have to generate the stylesheet to do it. But of
course, if you're using Saxon you can use the saxon:evaluate()
extension function.

> Maybe use a key?
>
> I'm confused (again!). I'm basically trying to rework some of my
> code, in part based around Geert's suggestions, but I can't really
> see how to do what I'm wanting to do (which is to be able to work on
> content from external files). It seems, for example, that I cannot
> use a key on content I want to access via the doc function.
>
>         <xsl:variable name="bibrecord" select="doc(concat('bib-data/',
> $bibkey, '.mods'))" />
>         <xsl:key name="biblio" match="$bibrecord//mods:mods" use="@ID" />

The document that's searched when you call the key() function is the
current document at the time of the call. So you should do:

<xsl:key name="biblio" match="mods:mods" use="@ID" />

and then something along the lines of:

<xsl:for-each select="$bibrecord/key('biblio', $bibkey)">
  ...
</xsl:for-each>

though I think that you need $bibkey to be defined as:

<xsl:variable name="bibkey" select="//db:bilioref/@linkend" />

since the <biblioref> elements can occur anywhere within the (source)
document.

Note that the path "$bibrecord/key('biblio', $bibkey)" is newly
allowed in XPath 2.0, and makes searching documents using keys a whole
lot easier than it used to be.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

Current Thread