Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I do this compare using XSLT ??

Status
Not open for further replies.

cheguvera

Programmer
Oct 13, 2005
32
GB
Hi all,

I have a XML like ,

<info>
<type>A</type>
<value1>ZZZZZZZ</value1>
<value2>YYYYYYY</value2>
</info>
<info>
<type>B</type>
<value1>ZZZZZZZ</value1>
<value2>YYYYYYY</value2>
</info>

With XSLT I would like to code logic like,

if value of <type> is 'A'
then
output value of <value1>
end if

if value of <type> is 'B'
then
output value of <value2>
end if

How can I do that? what can be the best syntex for it?
Is that possible without using variables?

Please help.

Regards
 
The way you ask it sounds like you can get it done through variable. How does it look like? Is there something that displeases you using variable?
 
Hi All,

Thanks for your reply.

Actually, I was not able to find syntax of string comparison in the <xsl:if . Everywhere I see on the internet, all the examples were showing numeric comparisons.

But, now its sorted out.
I can easily do it without using variables.

I can simply do it by,

<xsl:choose>
<xsl:when test="type = 'A'" >
<display><xsl:value-of select="value1" /></display>
</xsl:when>
<xsl:when test="type = 'B'" >
<display><xsl:value-of select="value2" /></display>
</xsl:when>
</xsl:choose>

It was as simple as that.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top