• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

preceding-sibling cannot use passed in value

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 28307
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
No, tomorrow we rule the world! With this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic