Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

preceding-sibling cannot use passed in value

 
Jay Olsen
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I run into a strange problem with preceding-sibling in xslt. The issue occurs when I pass in parameters to an xsl style sheet and try to use it with the preceding-sibling expression.

So we have the following xsl fragment

<td ><xsl:value-of select="preceding-sibling::*[$2]/@VAL"/></td>

which steps back 2 and retrieves the VAL node at that line. This works fine however I now want to pass in the value to step back as a parameter to the xsl style sheet. So the xsl fragment changes to the following with the $index value passed when the script is called.


<td ><xsl:value-of select="preceding-sibling::*[$index]/@VAL"/></td>

and call the style sheet as follows

<xslt
in="${xmlfile}"
out="${htmlfile}"
processor="trax"
style="${style}">
<param name="index" expression="2"/>
</xslt>

However, the preceding-sibling statement does not work when the value is passed in like this and no step back takes place.

If I print out the value of index in the xsl templates using the following


<xsl:value-of select='$index' />

I get the correct value.

If I declare the index variable in the xsl style sheet itself as follows

<xsl:variable name="index" select="2"/>

it works fine when passed to the preceding-sibling.

What is different between the passed in variable and the global variable declared in the style sheet?

Any help greatly appreciated.

Thanks
 
Paul Clapham
Sheriff
Pie
Posts: 20945
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean

(with 2 instead of $2)? If so then I think perhaps the difference is that your parameter is a string, not a number, so your parameterized XPath behaves the same as this one would:

If that's the case then there's a function named something like "number" which converts a string to a number.
 
Jay Olsen
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is exactly it. The following syntax works for me

<xsl:value-of select="preceding-sibling::*[number($index)]/@VAL"/>

where $index is the value passed into the style sheet.

Thank you very much.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic