[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: "xsl:if" - Comparing two elements

Subject: RE: "xsl:if" - Comparing two elements
From: "Pete Beazley" <pete@xxxxxxxxxxxxxxxxx>
Date: Wed, 2 Jun 1999 16:32:21 -0400
xsl if compare strings
Mark -

Try changing ../bestReturn to //bestReturn in your test in order to match
bestReturn regardless of where it is located in your document - that seemed
to do the trick on my system using IE5.

P.S. You might want to send future messages in plain text.  Yours came
through as RTF attachments. I've included your message in plain text for
those not able to open the RTF attachments.

--------
Pete Beazley - mailto:pete@xxxxxxxxxxxxxxxxx
ClearlyOnline, Inc.
XML-based Web Sites & XML services
http://www.clearlyonline.com
1-724-942-1912    1-724-941-3698 fax


> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxx
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxx]On Behalf Of
> markbender@xxxxxxxxxxxxxxxxxxxxxx
> Sent: Wednesday, June 02, 1999 3:51 PM
> To: XSL-List@xxxxxxxxxxxxxxxx
> Subject: "xsl:if" - Comparing two elements
>
>
>Greetings,

I'm having an extremely frustrating time trying to compare two xml elements
using the following command:

<xsl:if test="ThisThing[. = ThisOtherThing]">do this</xsl:if>

Heck, it won't even work if I try ThisThing[. = ThisThing]. The only way I
can get this to work is if I acutally compare "ThisThing" to a string
 ThisThing[. = '12345'] ).

Here's an example:

*********** EXAMPLE XML ********************

<?xml version="1.0"?>
<portfolio xmlns:dt="urn:schemas-microsoft-com:datatypes">
  <bestReturn>ZCXM</bestReturn>
  <stock exchange="nyse">
    <name>zacx corp</name>
    <symbol>ZCXM</symbol>
    <price dt:dt="number">28.875</price>
  </stock>
  <stock exchange="nasdaq">
    <name>zaffymat inc</name>
    <symbol>ZFFX</symbol>
    <price dt:dt="number">92.250</price>
  </stock>
  <stock exchange="nasdaq">
    <name>zysmergy inc</name>
    <symbol>ZYSZ</symbol>
    <price dt:dt="number">20.313</price>
  </stock>
</portfolio>

*********** EXAMPLE XSL ********************

<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl"
result-ns="http://www.w3.org/TR/REC-html">
  <xsl:template match="/">
    <HTML>
      <BODY>
	<B>Best Historical Return: </B><xsl:value-of
select="portfolio/bestReturn"/>
	<BR/><BR/>
	<B><I>My Portfolio</I></B><BR/>
        <TABLE BORDER="2">
          <TR>
            <TD><B>Symbol</B></TD>
            <TD><B>Name</B></TD>
            <TD><B>Price</B></TD>
            <TD><B>Best Return</B></TD>
          </TR>
          <xsl:for-each select="portfolio/stock">
            <TR>
              <TD><xsl:value-of select="symbol"/></TD>
              <TD><xsl:value-of select="name"/></TD>
              <TD><xsl:value-of select="price"/></TD>
              <TD>

<!-- HERE'S MY PROBLEM -->

		<xsl:if test="symbol[. = ../bestReturn]">Yes</xsl:if>

<!-- THE EXAMPLE BELOW WORKS, BUT IT'S COMPARING TO A STRING RATHER THAN
ANOTHER ELEMENT-->

		<xsl:if test="symbol[not(. = 'ZCXM')]">No</xsl:if>
	      </TD>
            </TR>
          </xsl:for-each>
        </TABLE>
      </BODY>
    </HTML>
  </xsl:template>
</xsl:stylesheet>

******************************************

What am I doing wrong?  Please help me, for sanity's sake.

--Mark



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.