Re: [xsl] variable in xpath

Subject: Re: [xsl] variable in xpath
From: "James Carlyle" <james.carlyle@xxxxxxxxxxxx>
Date: Fri, 15 Nov 2002 11:56:45 -0000
I'll take a shot at answering this.


> How do I obtain and copy the node <adesc> of File2 using the above
> $path variable? Something like the below one:
>
> <xsl:template match="node()">
>     <xsl:copy-of select="document(File2.xml)/$path.."/>
> </xsl:template>

I assume that you want to process file 1, but cross check in file 2 for
additional elements to copy into file 1.  You want to use an XPath
expression like element[1]/child[1]/a[1] (note I have added positions) to
reference the appropriate point in file 2.  Is my understanding correct?

You can't evaluate dynamic XPath expressions in the body of a select clause.
So what you have written won't work.  If the structure element/child/a is
fixed, you could use a nasty expression like

<xsl:template match="a">
<xsl:copy-of
select="document(File2.xml)/element[position()=count(current()/../../precedi
ng-sibling::element)+1]/child[position()=count(current()/../preceding-siblin
g::child)+1]/a[position()=count(current()/preceding-sibling::a)+1]/adesc"/>
</xsl:template>

There are probably 2 other ways that I can think of for solving this
problem, but I can't address and test them right now.  I might try and post
a follow up message later.

Hope this helps,

James Carlyle
www.takepart.com


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


Current Thread