This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan 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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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
Author

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

<personal>
<postaladdress>
<region>VA</region>
</postaladdress>
</personal>

And

<records>
<caseinformation><region>VA</region></caseinformation>
<caseinformation><region>CA</region></caseinformation>
<caseinformation><region>TX</region></caseinformation>
</records>

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


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

</xsl:if>

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
Bartender

Joined: Jul 13, 2001
Posts: 3150
http://www.w3schools.com/xsl/xsl_languages.asp 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--
</xsl:if>
</xsl:for-each>


Spritle Software Blogs
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to use variable in XSLT if condition
 
Similar Threads
Need help with XSLT
XML Transformation
break the loop in XSL
Need help with some conditional logic
XSLT - Getting Parent Node based on child node