xsl-list
[Top] [All Lists]

RE: Accessing the main document from a document()

2005-08-19 06:02:01
First, declare a global variable

<xsl:variable name="main" select="/"/>

Then you can use filter expressions such as

$main/data/value[(_at_)name=current()/@name]

when the context node is a parameter.

If the main document is large, then using keys is more efficient. In XSLT
2.0:

<xsl:key name="k" match="data/value" use="@name"/>

then (again from a parameter element) key('k', @name, $main) to do the join.

In 1.0 you have to circumlocute:

<xsl:variable name="keyval" select="@name"/>
<xsl:for-each select="$main">
  ... select="key('k', $keyval)"
</

because key() always selects in the current document.

Michael Kay
http://www.saxonica.com/ 

-----Original Message-----
From: Hans Hübner [mailto:hans(_dot_)huebner(_at_)gmail(_dot_)com] 
Sent: 19 August 2005 13:20
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Accessing the main document from a document()

Hi,

I am trying to write an XSL stylesheet that displays the data of the
document it is attached to under the control of a second document. 
This second document describes the formatting and data types of the
data in the main document.  It also defines the order in which the
fields from the main document are displayed.

Main document:

<?xml-stylesheet type="text/xsl" href="stylesheet.xsl" ?>
<data device-type="foo">
 <value name="a">blah</value>
 <value name="b">blub</value>
</data>

Formatting document:

<definitions>
 <device type="foo">
  <parameter name="b">... formatting instructions for field 
b..</parameter>
  <parameter name="a">... formatting instructions for field 
a...</parameter>
 </device>
 <device ... more devices>
 </device>
</definitions>

From the style sheet, I am now selecting the right device definition
and iterate through it's parameters, generating output on the way. 
For each of the parameters, I now need access to its value as set in
the main document.  How do I do that?

Thanks in advance!
Hans

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--





--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>