xsl:variable

Discussion in 'XML' started by ShakyMobo, Mar 1, 2005.

  1. ShakyMobo

    ShakyMobo Guest

    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?
    ShakyMobo, Mar 1, 2005
    #1
    1. Advertising

  2. 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
    David Carlisle, Mar 1, 2005
    #2
    1. Advertising

  3. ShakyMobo

    Tim Perkuhn Guest

    ShakyMobo wrote:

    > 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?


    Variables can be used in a function.
    Read this: http://www.dpawson.co.uk/xsl/sect2/N6191.html#d7980e37
    Tim Perkuhn, Mar 4, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Karsten Weinert
    Replies:
    3
    Views:
    991
    Karsten Weinert
    Jul 5, 2004
  2. MC
    Replies:
    1
    Views:
    7,237
    David Carlisle
    Mar 24, 2005
  3. Replies:
    1
    Views:
    3,590
    A. Bolmarcich
    May 27, 2005
  4. Afshar Mohebbi
    Replies:
    5
    Views:
    6,030
    Afshar Mohebbi
    Jun 26, 2006
  5. Replies:
    2
    Views:
    9,247
    Martin Honnen
    Sep 5, 2006
Loading...

Share This Page