#43 Assignment to variable makes a difference. Why?

closed
nobody
None
5
2012-10-08
2006-05-03
Oliver Meyer
No

Hi Everybody,

in the attached stylesheet, I do an xsl:for-each on a
set of strings. Success in accessing the context node
then seems to depend on wether I assign its string
value to a variable first (lines 42-45):

42: <xsl:value-of select="."/>
43: <xsl:value-of select="count($TopicSelections&lt;span&gt;[@value=string(.)]&lt;/span&gt;)"/>
44: <xsl:variable name="v" select="string(.)"/>
45: <xsl:value-of select="count($TopicSelections&lt;span&gt;[@value=$v]&lt;/span&gt;)"/>

The output of lines 43 and 45 should not differ, but
they do. Only line 45 works.

I attached the stylesheet, an input file, and my result
file.

Please enlighten me about the conversion of atomic
values, sequences and trees that should cause this
behaviour if it is no bug.

BTW: I use saxonB.8-7

Best Wishes,
Oliver

Discussion

  • Oliver Meyer
    Oliver Meyer
    2006-05-03

    Sample Input File

     
  • Oliver Meyer
    Oliver Meyer
    2006-05-03

    The style sheet.

     
    Attachments
  • Oliver Meyer
    Oliver Meyer
    2006-05-03

    The result

     
    Attachments
  • Oliver Meyer
    Oliver Meyer
    2006-05-03

    Logged In: YES
    user_id=203018

    I also tried with 8.7.1j but to no avail.

     
  • Michael Kay
    Michael Kay
    2006-05-03

    Logged In: YES
    user_id=251681

    A predicate changes the context node: so within the square
    brackets "." (and therefore string(.)) gives a different
    result from the same expression evaluated outside the square
    brackets. The expression $TopicSelections[@value=string(.)]
    selects those items in $TopicSelections whose string-value
    is equal to their @value attribute (for example <e value="3">3</e>).

    If you don't want to use a variable, you can always use
    current().

    Michael Kay

     
  • Oliver Meyer
    Oliver Meyer
    2006-05-04

    Logged In: YES
    user_id=203018

    Thank you for that perfect answer. Thank you also for the
    pointer to current(). I ran into the problem of using an
    expression as above within a sort statement and that
    couldn't be solved with a variable.

    Thank you very much for your work, your helpfullness and
    your help.

     


Anonymous


Cancel   Add attachments