xsl-list
[Top] [All Lists]

Re: variable question

2004-11-10 14:01:51
Hi Bruce,

At 02:51 PM 11/10/2004, you wrote:
In XSLT 1.0 the only way to do this would be by using a stylesheet to generate your stylesheet.

Ugh.

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

Maybe use a key?

Nope. A key can be used to retrieve nodes dynamically, but it's a way around slow and tortuous XPaths (that is, an optimization that XPath offers itself), not a way of manipulating XPath.

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.

You mean the document() function, I take it. But no, you're not going to be able to use key() to retrieve nodes dispersed throughout an arbitrary number of external documents. It works on one document at a time.

If you know all your nodes of interest are in a single document, you can change context to that document and use key() therein:

<xsl:variable name="bibrecord" select="document(concat('bib-data/', $bibkey, '.mods'))" />
<xsl:key name="biblio" match="mods:mods" use="@ID" />

<xsl:template match ...>
  <xsl:variable name="key-value" select="[your key value]"/>
  <!-- ... now changing context to the bibrecord document -->
  <xsl:for-each select="$bibrecord">
    <!-- ... now changing context to the key-retrieved element
             inside the bibrecord doc -->
    <xsl:for-each select="key('biblio', $key-value">
       ... do your thing ...
    </xsl:for-each>
  </xsl:for-each>
</xsl:template>

But I'm not sure that's quite enough to give you what you need. Maybe.

Cheers,
Wendell


======================================================================
Wendell Piez                            
mailto:wapiez(_at_)mulberrytech(_dot_)com
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================



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