RE: [xsl] Recursive evaluation of elements

Subject: RE: [xsl] Recursive evaluation of elements
From: "Rowan Sylvester-Bradley" <rowan@xxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 13 Dec 2009 19:26:21 -0000
Florent Georges wrote:

>I didn't look into the details, but it seems you simply want to expand
expressions recursively:
>as long as the result of an expansion contains curly braces, it should be
expanded itself.
>So at first glance, I would adapt the following:

    <xsl:matching-substring>
       <xsl:value-of select="
           saxon:eval(
               saxon:expression(regex-group(1)),
               $tablerow,
               $source
             )"/>
    </xsl:matching-substring>

>into the following (but as I said, I didn't look into the details,
>for instance would you have to adapt params, etc.):

    <xsl:matching-substring>
       <xsl:variable name="expanded" as="text()">
          <xsl:value-of select="
              saxon:eval(
                  saxon:expression(regex-group(1)),
                  $tablerow,
                  $source
                )"/>
       </xsl:variable>
       <xsl:apply-templates select="$expanded" mode="#current"/>
    </xsl:matching-substring>

Florent - Thanks for this suggestion. It does something interesting, but not
quite what I'm looking for! It will recursively evaluate expressions, but the
problem is that the context for the evaluation (i.e. the value of the
variables $p1 and $p2) is always that of the inner expansion. It therefore
generates:
<name>Item C (Second Class) delivered by Second Class</name>
Whereas what I need is:
<name>Item C (A nasty cheap one) delivered by Second Class</name>

It needs to evaluate the expression {concat($p2/../name, ' delivered by ',
$p1/name)} where $p2/../name needs to be the result of the expression Item C
({$p1/name}) in the context of the outer expansion, i.e. with $p1 set to the
first <row> of Table1. What it actually did, I think, is to re-evaluate the
expression Item C ({$p1/name}) in the context of the inner expansion, i.e.
with $p1 set to the first row of Table 2. Hence we got "Second Class" twice.

I've tried all sorts of ways of developing your approach to make it do what I
want, but nothing has worked so far.

Can anyone suggest a way of getting this to work?

Many thanks - Rowan

Current Thread