Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 20th, 2006, 05:23 PM
Authorized User
 
Join Date: Apr 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSL Params inside When Test

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.

 
Old April 21st, 2006, 04:20 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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
 
Old April 21st, 2006, 04:22 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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
 
Old April 21st, 2006, 05:45 AM
Authorized User
 
Join Date: Apr 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Michael, much appreciated.






Similar Threads
Thread Thread Starter Forum Replies Last Post
xsl:when test - comparison problem pelicanPaul XSLT 1 June 29th, 2007 04:45 AM
Sorting a xsl:if test="position()" charmaigne XSLT 2 April 12th, 2006 04:42 AM
XSL Test tclancy XSLT 2 February 3rd, 2006 02:49 PM
<xsl:if test="" Question kwilliams XSLT 2 August 9th, 2005 08:30 AM
Using xsl:if test attributes rdavisiii XSLT 4 November 9th, 2004 12:24 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.