Jeni Tennison
> 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/*)
|