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

Re: Compare data from different XML-files

Subject: Re: Compare data from different XML-files
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Mon, 13 Nov 2000 09:37:49 +0000
compare data in xml
Fredric,

> I want to compare XML-data from two different XML-sources-files in my
> XSL-stylesheet, how do I do that? 

The function that you need is the document() function, which pulls in
information from a named XML file.  The way I would usually arrange
this is to have the input to the XSLT stylesheet be some XML that
describes the position of the two files that you want to compare:

--- input.xml ---
<files>
  <file href="file1.xml" />
  <file href="file2.xml" />
</files>
---

You can then access the two documents and put them into global
variables using:

<xsl:variable name="file1"
              select="document(/files/file[1]/@href, /)" />
<xsl:variable name="file2"
              select="document(/files/file[2]/@href, /)" />

[Note the second argument to document() ensures that the file names
are resolved relative to your input.xml document rather than the
stylesheet.]

An alternative way of reaching this state is to use one of the files
as the input to the stylesheet, and name the other as a parameter to
the stylesheet.  You can then use:

<xsl:param name="comparison-file" />
<xsl:variable name="file1" select="/" />
<xsl:variable name="file2" select="document($comparison-file, /)" />

When you have the two document trees as separate variables, you can
compare them however you want. For example, to test whether the names
of the document elements are the same you could use:

  name($file1/*) = name($file2/*)

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



 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.