• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to use variable in XSLT if condition

 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author and deputy
Posts: 3150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
 
reply
    Bookmark Topic Watch Topic
  • New Topic