xsl-list
[Top] [All Lists]

Re: [xsl] xpath-default-namespace with a variable

2011-09-19 08:15:14
Murray McDonald 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.

Can anyone tell me if this a bug or expected behaviour?

Well the XSLT 2.0 specification for values taking an attribute value template uses a syntax like
  xsl:element name = { qname }
(i.e. curly braces are used).
For the xpath-default-namespace the syntax is defined on xsl:stylesheet without curly braces:

<xsl:stylesheet
  id? = id
  extension-element-prefixes? = tokens
  exclude-result-prefixes? = tokens
  version = number
  xpath-default-namespace? = uri

so the syntax you want is not supported.




--

        Martin Honnen --- MVP Data Platform Development
        http://msmvps.com/blogs/martin_honnen/

--~------------------------------------------------------------------
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>
--~--