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

RE: Global location path confusion

Subject: RE: Global location path confusion
From: "Michael Kay" <mhkay@xxxxxxxxxxxx>
Date: Thu, 22 Feb 2001 23:48:53 -0000
stylesheet path location
> I have the following XSLT stylesheet:
>
> <?xml version="1.0" encoding="iso-8859-1"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> version="1.0">
>
>   <xsl:template match="doc">
>    <doc>
>      <xsl:apply-templates/>
>    </doc>
>   </xsl:template>
>
>   <xsl:template match="a">
>    <x title="{/doc/@title}"/>
>   </xsl:template>
>
>   <xsl:template match="b">
>    <xsl:param name="content">
>      <a/>
>    </xsl:param>
>    <xsl:apply-templates select="$content"/>
>   </xsl:template>
>
> </xsl:stylesheet>
>
Note, this will only work with an XSLT 1.1 processor that allows implicit
conversion of result-tree-fragments to node-sets. (Eg. recent releases of
Saxon).

> Then I feed it the following xml:
>
> <?xml version="1.0" encoding="iso-8859-1"?>
>
> <doc title="abc">
>   <a/>
>   <b/>
> </doc>
>
> This results in the following output xml:
>
> <doc>
>   <x title="abc"></x>
>   <x title=""></x>
> </doc>
>

When you process the second <a/> node, the template rule looks for the title
attribute of the doc element that is a child of the root of the tree
containing the <a/> node, and there isn't one.

It's a common misunderstanding, exacerbated by the terminology of the spec,
that "/doc/x" is an "absolute" location path (or "global" in your words). It
isn't: it's relative to the root of the tree that contains the context node.

Mike Kay


 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.