Subject: XSL Params inside When Test
Posted By: shasto100 Post Date: 4/20/2006 5:23:57 PM
Hi, i have the following when statement, inside the test I'm tring to use '$rowNo' parameter inside the string, because I'm using a recursive loop. Everything else works great but I want to be able to join, 1, 2 & 3 together.

1) <xsl:when test="contains(substring(//helper/row/row
2) $rowNo
3) /text(), $helperNo,2), '--')">

<xsl:when test="contains(substring(//helper/row/row$rowNo/text(), $helperNo,2), '--')">

I've tried concat (dont work, comes up with NaN2 in the output):

<xsl:when test="contains(concat(substring(//helper/row/row,$rowNo,/text(), $helperNo,2)), '--')">

-----------------------------------------
Input:
//helper/row

<row num="1">
<row1>01020304--0506070809--10111213</row1>
<row2>14--------15----------16------</row2>
<row3>17------18------------19------</row3>
<row4>20------21--------2223--------</row4>
<row5>------24--------25------------</row5>
</row>


------------------

Any help much much appreicated.


Tried the following too:

<xsl:variable name="starter" select="'substring(//helper/row/row'" />
<xsl:variable name="finisher" select="'/text()'" />
<xsl:variable name="finisher2" select="',$helperNo,2)'" />

...
<xsl:value-of select="$starter+$rowNo+$finisher+$finisher2"/>
...


Doesn't work either! :(

PLEASE PLEASE PLEASE - Just want to know if this is possible really (and how if available).

Thank you.

Reply By: mhkay Reply Date: 4/21/2006 4:20:17 AM
Variables in XSLT work like in languages such as C, Java, or Javscript: they can be used anywhere you can use a *value*. They don't work like variables in a shell-script or other macro language, where they can replace any part of the text of an expression.

Using element names like <row1>, <row2> is pretty poor XML design. This is what attributes are designed for: <row nr="2">. But if you're saddled with this kind of structure, you can use

.../*[name() = concat('row', $rownr)]/...

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply By: mhkay Reply Date: 4/21/2006 4:22:29 AM
Again you are making the mistake of thinking that a variable holds a piece of XPath expression text. It doesn't - it holds a value. Use variables only where you might use say a number 2 or a string literal 'fred'.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply By: shasto100 Reply Date: 4/21/2006 5:45:51 AM
Thanks Michael, much appreciated.


Go to topic 43224

Return to index page 307
Return to index page 306
Return to index page 305
Return to index page 304
Return to index page 303
Return to index page 302
Return to index page 301
Return to index page 300
Return to index page 299
Return to index page 298