This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: compare two lists of values question


Hal,

The following stylesheet should do the trick:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  <xsl:output method="text"/>
  <xsl:key name="us_merchants" match="USMerchants/name" use="."/>
  <xsl:key name="uk_merchants" match="UKMerchants/name" use="."/>

  <xsl:template match="/">
     <xsl:for-each select="/Merchants/*/name">
       <xsl:if test="( key( 'us_merchants', . ) and
                       not( key( 'uk_merchants', . ) )
                     )
                     or
                     ( key( 'uk_merchants', . ) and
                       not( key( 'us_merchants', . ) )
                     )">
         <xsl:value-of select="."/>
         <xsl:text> is not in both lists.&#x0D;&#x0A;</xsl:text>
       </xsl:if>
    </xsl:for-each>
  </xsl:template>

</xsl:stylesheet>

Please note that I changed the name of the
UKMerchant element to "UKMerchants".

Hope this helps.

Bob

<sig name    = 'Bob Lyons'
     title   = 'XML Consultant'
     company = 'Unidex, Inc.'
     phone   = '+1-732-975-9877'
     email   = 'boblyons@unidex.com'
     url     = 'http://www.unidex.com/'
     product = 'XML Convert: transforms flat files to XML and vice versa' />

-----Original Message-----

I'm assuming this is kind of a novice level question.
I need to compare two lists of values and display the value of any name
element not in both lists.
The xml is like this:
<Merchants>
<USMerchants>
	<name>store1</name>
	<name>store2</name>
	<name>store3</name>
	<name>store4</name>
	<name>store5</name>
	<name>store6</name>
</USMerchants>
<UKMerchant>
	<name>store1</name>
	<name>store2</name>
	<name>store3</name>
	<name>store4</name>
	<name>store5</name>
	<name>store99</name>
</UKMerchant>
</Merchants>

Using MSXML3 parser.

Thanks in advance,
Hal Friedlander


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]