This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes how to use variable in XSLT if condition Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "how to use variable in XSLT if condition" Watch "how to use variable in XSLT if condition" New topic

how to use variable in XSLT if condition

Archana Annamaneni
Ranch Hand

Joined: Jan 29, 2003
Posts: 147
I have a situation like this

In my XML I have




I have to delete all the caseinformation nodes whose region is not VA.

For that i stored first region value in a variable called regionvalue and trying to compare
like this

<xsl:for-each select="caseinformation">
<xsl:if $regionvalue=<xsl:value-of select="/records/caseinformation/region"/>>


it is giving the error ,I am still in learning stage in XSLT.

Please somebody tell me how to solve this
Balaji Loganathan
author and deputy

Joined: Jul 13, 2001
Posts: 3150 got a friendly tutorials on xsl,xpath,xsd and so on. do read them

Your xslt gives error because xsl:if test condition should go under test attribute of xsl:if..
something like..
<xsl:for-each select="caseinformation">
<xsl:if test="$regionvalue=region"/>
--execute rule--

Spritle Software Blogs
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: how to use variable in XSLT if condition
It's not a secret anymore!