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]
Other format: [Raw text]

RE: Select a node in another xml-document




-----Original Message-----
From: owner-xsl-list@lists.mulberrytech.com
[mailto:owner-xsl-list@lists.mulberrytech.com]On Behalf Of
Mukul.Mudgal@etindia.com
Sent: Monday, May 27, 2002 11:59 AM
To: xsl-list@lists.mulberrytech.com
Subject: Re: [xsl] Select a node in another xml-document

=========================================

Microsoft XML Core Services (MSXML) 4.0 - XSLT Developer's Guide

Process Multiple XML Documents
You can incorporate XML from external documents by using the document()
function. This function takes as an argument either the relative or absolute
URL of the document you want to retrieve. The URL is specified as a string
or as a node in which the text value of that node resolves to a URL. For
example, the following statement loads the Ancillary.xml document and holds
it in the ancillary variable.

<xsl:variable name="ancillary" select="document('ancillary.xml')"/>
The Ancillary.xml document is located in the same directory as the original
source XML document, and returns the resulting node set in the variable
named ancillary. Alternatively, you could declare this ancillary document in
the Sales.xml file:

...
<sales>
   <ancillary_doc href="ancillary.xml"/>
...
</sales>
In this case, you would reference it in Transform.xsl as follows:

<xsl:variable name="ancillary" select="document(//ancillary_doc/@href)"/>
In the first case, the argument of the document function is a string. In the
second case, the argument is a node set.

With document(), you load the entire contents of the document, and then
select elements from the document by using XML Path Language (XPath)
expressions.

In this exercise, first you will create the external document,
Ancillary.xml. This document contains a watermark and a copyright notice for
the sales report. Then you will add code to Transform.xsl to retrieve the
Ancillary.xml file and format the data in that file.

To create Ancillary.xml

In your HTML or text editor, open a new, empty file.
Add the following code to the file:
<?xml version='1.0'?>
<document>
   <watermark>Scootney Publishing</watermark>
   <copyright>Copyright 2000, Scootney Publishing. All Rights
Reserved.</copyright>
</document>
In the same folder as Sales.xml, save the file as Ancillary.xml. Then close
the file.
To update Transform.xsl to extract data from Ancillary.xml

In your HTML or text editor, open Transform.xsl and locate the <body> line.
Immediately below the <body> line, add the following code:
<xsl:variable name="ancillary" select="document('ancillary.xml')"/>
This loads the Ancillary.xml document and returns the resulting node set in
the variable named ancillary.

Directly below the line that you just added, add the following code:
<DIV style="position:absolute;font-size:96;font-family:Times New Roman;
      color:#F0F0F0;z-index:-1">
   <xsl:value-of select="$ancillary//watermark"/>
</DIV>
This code reads the <watermark> element from Ancillary.xml and formats the
string it contains as a watermark. The XPath expression,
$ancillary//watermark, resolves to all <watermark> elements in the
Ancillary.xml file.

Note   As an alternative to the variable declaration, you can accomplish the
same effect by referencing the external XML document directly, as follows:
<xsl:value-of select="document('ancillary.xml')//watermark"/>
However, using a variable to hold the external document is more efficient if
you need to reference the document more than once, as is the case in this
exercise.
Immediately above the </body> tag, add the following code:
<DIV style="font-size:9">
   <xsl:value-of select="$ancillary//copyright"/>
</DIV>
These lines insert and format the copyright notice string from
Ancillary.xml.

Save Transform.xsl.
To view the source and ancillary files

In Internet Explorer, press F5 to refresh the display of Sales.xml.


> This is part of MS documentation for XSLT 1.0. Check it out. The entire
document
>in .chm format (Windows Help)is available with the MSXML 4.0 Parser free
somewhere at
>www.microsoft.com

------------------

Vladimir Stanciu - vlads@wdd.ro




 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]