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

RE: Accessing the main document from a document()

Subject: RE: Accessing the main document from a document()
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 19 Aug 2005 14:02:01 +0100
RE:  Accessing the main document from a document()
First, declare a global variable

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

Then you can use filter expressions such as

$main/data/value[@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.huebner@xxxxxxxxx]
> Sent: 19 August 2005 13:20
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  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

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.