[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Problems to interpret an attribute value as an Xpa

Subject: Re: Problems to interpret an attribute value as an Xpath expression
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 10 Jan 2002 13:39:11 +0000
saxon evaluate example concat node
Hi Roman,

[Removed www-forms@xxxxxx from the CC list because we're not allowed
to cross-post on this list.]

> I'd like to use the value of a ref attribute as an XPath expression
> in my stylesheet. I want the processor to jump to the specified node
> and get the value from there. I used a "normal" <xsl:value-of
> select="@ref"/> ,but the processor didn't interpret it as an XPath
> expression but as a string.
> Does anyone know a method to tell the processor to use a source
> document's attribute value as an XPath expression in the stylesheet?

You can't do it in XSLT 1.0. Some processors support an extension
evaluate() function, so that you can do, for example:

  saxon:evaluate(concat('/xform:model/xform:instance', @ref))

Another alternative that might be feasible would be to construct a
path to the nodes that you want to refer to and use that as a key
value. This is difficult because key values have to be set using XPath
expressions, but it's doable if you're using a processor that supports
user-defined extension functions written in XSLT. For example, you
could do:

<xsl:key name="instance-data" match="xform:instance//*"
         use="my:path()" />

Where my:path was defined with something along the lines of:

<func:function name="my:path">
  <func:result select="concat(my:path(..), '/', name())" />

You could then use:

  key('instance-data', concat('xform:model/xform:instance', @ref))

to get hold of the relevant node from the instance data tree.

A third alternative might be feasible if the processor you're using
supports XPointer fragment identifiers in URLs. You might be able to
do something like:

  document(concat('#xpointer(/xform:model/xform:instance', @ref, ')'),

to get hold of the node that you want.

[This was one of the use cases that I pointed out for an evaluate()
 function in XPath 2.0.]



Jeni Tennison

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.