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

Re: xpath-default-namespace with a variable

Subject: Re: xpath-default-namespace with a variable
From: Andrew Welch <andrew.j.welch@xxxxxxxxx>
Date: Mon, 19 Sep 2011 14:21:38 +0100
Re:  xpath-default-namespace with a variable
On 19 September 2011 14:06, Murray McDonald <m.mcdonald@xxxxxxxxx> wrote:
> I am using XSLT 2 via AltovaXML.
>
> I have a need to look up "key" terms in an external glossary document.  The
> external document has a default namespace at the root level.  The code
works
> fine like this:
>
> <xsl:param name="GLOSSARY" select="'./working_files/glossary.xml'"/>
>
> <xsl:key name="definitions" match="glossentry" use="term/@key"
> xpath-default-namespace="http://www.abcdef.com/hij"/>
>
> <xsl:variable name="glossaryDocument" select="document($GLOSSARY)"/>
>
> ...
>
> <xsl:variable name="definition">
>        <xsl:for-each select="$glossaryDocument">
>                <xsl:value-of select="key('definitions',
> $normalizedText)/definition" xpath-default-namespace="
> http://www.abcdef.com/hij"/>
>        </xsl:for-each>
> </xsl:variable>
>
> After testing I decided to replace the "hardcoded" namespace with a
"global"
> variable.  I was surprised to find that this did not work.
>
> <xsl:variable name="glossNS" select="'http://www.abcdef.com/hij'"
> as="xs:anyURL"/>
>
> <xsl:key name="definitions" match="glossentry" use="term/@key"
> xpath-default-namespace="{$glossNS}"/>
>
> ...
>
>                <xsl:value-of select="key('definitions',
> $normalizedText)/definition" xpath-default-namespace="{$glossNS}"/>
>
> I've check the spec and I can't find anything to make me believe this
> shouldn't work but it's entirely possible I may have missed some subtlety.

You can't declare namespaces using AVTs.... I would just declare the
namespace with a prefix once on your root element and then use that in
the key definition:

<xsl:stylesheet ... xmlns:foo="http://www.abcdef.com/hij">

<xsl:key name="definitions" match="foo:glossentry" use="term/@key"/>



--
Andrew Welch
http://andrewjwelch.com

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.