xsl:variable

S

ShakyMobo

I've got two xml files, nr.1 one which among other elements contains
elements with Xpath expressions for selecting elements from the the 2. file

xml#1 (Metadata for xml#2)
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<cml doc="hello.xml">
<info>
<creator>MR X</creator>
<date>240205</date>
<range>/text[position()=1]</range>
</info>
....
</cml>

xml#2
<article>
<text>
Hello there!
</text>
<text>Hey man</text>
</article>


What I want to do is to use the first <range> element to select the
textelement from xml nr 2.
test.xsl

<xsl:variable name="content" select="document('hello.xml')/article"/>

<xsl:template match="/">
<xsl:for-each select="/cml/info">
....
get first "range" element
get value from xml#2 according to the range element
....

I first tried with variables but soon realized that the values couldn't be
changed, and I don't think variables works too good with expressions?
Any suggestions on how to accomplish this task?
 
D

David Carlisle

XSLT gives no standard mechanism for evaluating a string as an XPath
expression.


You have two choices.
Some systems (saxon, for example) have an evaluate() extension function
so you'd just go select="saxon:evaluate(concat($doc2,range))"

alternatively you need to proceed in two steps first generate a
stylesheet using an XSLt stylesheet that extracts the expresions from
xml1 and inserts them in suitable XSLT select attributes, then execute
this generated stylesheet.

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top