This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: How can i convert the variable value into xpath


Mike Ferrando wrote:
> Dear friends,
> I wonder if I am trying to do the same thing. What has come to my
> mind as a possibility is:
> 
> <xsl:variable name="try-this" select="${@LINK}"/>
> <xsl:copy-of select="$try-this"/>
> or
> <xsl:copy-of select="${@LINK}"/>
> 

First I can tell you why that won't work:

{} encapsulates an XPath expression only in certain types of attribute 
values called attribute value templates. XSLT instructions don't usually 
use AVTs; in general only literal result elements do.

And a variable is a named XPath/XSLT data object, not a text substitution
macro. You've been spoiled by Perl, it looks like.

> The nodes all have the same name element, but the attribute value is
> different. That same value matches the variable names of an
> xsl:include document. The end result is the node that is called by
> the template is matched to an array. When the array match is found,
> then the value of the attribute of that node in the array is then
> taken for the variable name. This attribute value which is now a
> variable is then called up to replace the node called by the
> template.

I'm sure Jeni will fully understand and give you a 6 page walkthrough on it, 
but I'll just say this:

Any references to variable names must be hard-coded; you can't calculate 
the variable name, not when you create it and not when you reference it.

But you do have many more options with the names of nodes. So what you should
do instead of using xsl:variable is just store the data in XML elsewhere,
either in another document that access via document('foo.xml'), or in your
stylesheet, which you can access as a source tree with document(''). To do the
latter, you should embed your data in a named template that you never call.
I'd just use a separate file, myself.

  <vars>
    <var name="n3">see...Manuscripts</var>
    <var name="n4">see...scores</var>
  </vars>

Now you can easily look for /vars/var[@name = current()/@LINK]

   - Mike
____________________________________________________________________________
  mike j. brown                   |  xml/xslt: http://skew.org/xml/
  denver/boulder, colorado, usa   |  personal: http://hyperreal.org/~mike/

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]