[xslt] Re: more on the xslt namespace pipeline issue



S Woodside wrote:
> Here's another go at the pipeline namespace problem.
> AxKit is 1.6.1
> Using libxml 20425, libxslt 10019 and libexslt 710

And at last we have the answer! It's pretty simple actually. One *crucial* thing 
to know here is that in AxKit, the two passes don't have an intermediate XML 
step, a DOM is passed straight from the first stylesheet to the second one. 
Using xsltproc, that is not the case: there is a temporary intermediate XML 
document stored in a file.

Let's narrow down to the problem:

> /=======================================================\
>  test1.xml
>  This is applied to the above instance file.
> \=======================================================/
> <?xml version="1.0"?>
> <xsl:stylesheet
>   xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
>   version="1.0"
>   >
> 
>   <xsl:template match="atest">
>     <btest>
>       <xsl:element name="rngform" namespace="http://simonwoodside.com/rng";>
>         <title>RNG Form</title>
>       </xsl:element>
>     </btest>
>   </xsl:template>
> </xsl:stylesheet>

Here you are creating three nested elements: btest in no namespace, rngform in 
the http://simonwoodside.com/rng namespace, and (important) title in no 
namespace. Using the JC notation, that is:

{}btest
{http://simonwoodside.com/rng}rngform
{}title

When passing a DOM around, what I believe is the correct namespace information 
will be passed around. However when you save to an intermediate file you get this:

> <btest>
>   <rngform xmlns="http://simonwoodside.com/rng";>
>     <title>RNG Form</title>
>   </rngform>
> </btest>

As we can see, thanks to namespace defaulting, we now have:

{}btest
{http://simonwoodside.com/rng}rngform
{http://simonwoodside.com/rng}}title

Which is an entirely different document. Properly serialising that would have 
required libxml to add xmlns='' on title, except that's only possible starting 
with namespaces 1.1. Another option would have been to add a random prefix to 
rngform, but that wouldn't be nice.

Unless I am solidly mistaken on how XSLT should treat namespace contexts in 
xsl:element, the bug is yours and the AxKit processing pipeline expresses the 
most logical output.

IIRC xsl:element/@name takes a QName. You should thus be able to fix your bug with:

   <xsl:element name="rng:rngform" namespace="http://simonwoodside.com/rng";>
     <title>RNG Form</title>
   </xsl:element>

which should generate:


  <btest>
    <rng:rngform xmlns:rng="http://simonwoodside.com/rng";>
      <title>RNG Form</title>
    </rng:rngform>
  </btest>

-- 
Robin Berjon <robin.berjon@expway.fr>
Research Engineer, Expway        http://expway.fr/
7FC0 6F5F D864 EFB8 08CE  8E74 58E6 D5DB 4889 2488




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]