[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] How to query a temporary document in a variable


Subject: Re: [xsl] How to query a temporary document in a variable
From: Jean-Pierre Bergamin <jpbergamin@xxxxxxxxx>
Date: Mon, 10 Sep 2012 15:39:08 +0200

I found the answer here: http://www.dpawson.co.uk/xsl/rev2/namespace2.html
I cite: "if an xpath-default-namespace is in force, then there is no
way to select elements in no namespace. But you can reset it, for any
region of the stylesheet, by putting xpath-default-namespace="" on any
XSLT element."

So in my case this will work:
<xsl:value-of xpath-default-namespace=""
select="$propertyMap/entry[@key='foo']" />


Best regards,
James


2012/9/10 Jean-Pierre Bergamin <jpbergamin@xxxxxxxxx>:
> Hi Martin
>
> I indeed use a default namespace by declaring it with xpath-default-namespace.
> An complete example stylesheet looks like this:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:er="http://www.junisphere.net/eRanger"
>         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0"
>         xpath-default-namespace="http://graphml.graphdrawing.org/xmlns">
>
>         <xsl:output encoding="iso-8859-1" method="text" />
>
>         <xsl:variable name="propertyMap">
>                 <entry key="foo">foo value</entry>
>                 <entry key="bar">bar value</entry>
>         </xsl:variable>
>
>         <xsl:template match="/">
>                 <xsl:value-of xmlns="" select="$propertyMap/entry[@key='foo']" />
>         </xsl:template>
> </xsl:stylesheet>
>
> If xpath-default-namespace is deleted, "foo value" is output as
> expected. How can I get the expected result with
> xpath-default-namespace set?
>
>
> Best regards,
> James
>
>
>
> 2012/9/10 Martin Honnen <Martin.Honnen@xxxxxx>:
>> Jean-Pierre Bergamin wrote:
>>>
>>> Hello xslt-users
>>>
>>> I'm trying to use a temporary document as a lookup table with saxon
>>> 9.4 using xslt 2.0. The solution is also proposed in this
>>> stackoverflow answer:
>>> http://stackoverflow.com/questions/3626118/xslt-creating-a-map-in-xslt
>>>
>>> But I'm not getting any results when I query the variable that holds
>>> the temporary document:
>>>
>>> <xsl:variable name="propertyMap">
>>>         <entry key="foo">foo value</entry>
>>>         <entry key="bar">bar value</entry>
>>> </xsl:variable>
>>>
>>> <xsl:template match="/">
>>>         <xsl:value-of select="$propertyMap/entry[position() = 1]"/>
>>>         <xsl:value-of select="$propertyMap/entry[@key='foo']"/>
>>>         <xsl:value-of select="$propertyMap[1]"/>
>>> </xsl:template>
>>>
>>> The first two value-of expressions do not output anything, whereas the
>>> third one outputs the whole propertyMap.
>>>
>>> Any idea what I'm missing here?
>>
>>
>>
>> Perhaps the stylesheet root element defines some default namespace (e.g.
>>   <xsl:stylesheet
>>      xmlns="http://www.w3.org/1999/xhtml" ...>
>> ) which gets into the way for the temporary elements you want to create so
>> use e.g.
>>   <xsl:variable xmlns="" name="propertyMap">...</xsl:variable>
>>
>> That's a guess of course, show us more context I guessed wrong.
>>
>>
>> --
>>
>>         Martin Honnen --- MVP Data Platform Development
>>         http://msmvps.com/blogs/martin_honnen/


Current Thread
Keywords