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

Re: document()

Subject: Re: document()
From: Stuart Brown <stuart.brown@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 13 Feb 2002 12:36:46 +0000
stuart brown oxford
>
> Thanks for your reply!  Do you ( or anybody else) happen to know how to use
> the document() function to get to the root node of the xml file that you're
> applying your stylesheet to?  Or are there better, alternative ways of
> getting your
> xml file root node??

It might not be the most sophisticated solution, but I define a global parameter
docURI, use references to this, and pass the value to the processor at the
command line, thus:

<xsl:transform [blah blah]>
  <xsl:param name="docURI">index.xml</xsl:param><!-- My default -->
  <xsl:template match="foo">
    <xsl:for-each select="document('someOtherDoc.xml')>
    <!-- We move the context into some other doc -->
      <xsl:for-each select="document($docURI)">
      <!-- And here we are back in the original (whatever it is) -->
      </xsl:for-each>
    </xsl:for-each>
  </xsl:template>
</xsl:transform>

Command line (e.g.):  saxon foo.xml bar.xsl docURI="foo.xml"

> Even more confusing,
> he says that  document('') is used to get the root node of the
> stylesheet - what
> would you do with that?  Didn't he mean the root node of the xml file you're
> applying the stylesheet to?

No -- the stylesheet itself.  If there is some static data, for instance US
State name/abbreviation equivalencies to which you will be referring at various
points, you can set up the following kind of system:

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform
  xmlns:lookup="lookup-place"
  exclude-result-prefixes="book">

<lookup:us>
  <lookup:state abbr="CA">California</lookup:state>
  <lookup:state abbr="NY">New York</lookup:state>
  ...
</lookup:us>

and then you know you have this information irrespective of the actual file you
are processing, and can get at it anywhere within the style sheet with, for
instance,

<xsl:value-of select="document(' ')//lookup:state[@abbr=$myState]">

Stuart

============
Stuart Brown
Text Encoding Initiative
Oxford, UK


 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.