xsl-list
[Top] [All Lists]

RE: Literal result element namespace differs from xsl:eleme nt namespace

2003-12-18 01:39:47
Thanks Michael & David, that confirms my suspicions. Drat!

I'd just gone through everything in Michaels's book on namespaces, but I
couldn't quite nail it. Nice to get an answer from the top :)

Rick

-----Original Message-----
From: Michael Kay [mailto:mhk(_at_)mhk(_dot_)me(_dot_)uk]
Sent: 17 December 2003 19:01
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] Literal result element namespace differs from
xsl:element namespace


From this evidence, libxslt appear to be getting it wrong, and you
should raise this with the supplier (or just switch to a different
processor).

Michael Kay

-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com 
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com] On Behalf Of 
Jones, Rick
Sent: 17 December 2003 16:59
To: 'XSL-List(_at_)lists(_dot_)mulberrytech(_dot_)com'
Subject: [xsl] Literal result element namespace differs from 
xsl:element namespace


I'm getting a problem with namespaces, where the output 
document needs to change its namespace in the middle. Saxon 
works OK, but libxslt behaves differently.

Here's a highly simplified example - the intended output is:

<?xml version="1.0"?>
<Message xmlns="http://me.envelope";>
  <Header>
    <Title>My document</Title>
    <From>someone</From>
  </Header
  <Body xmlns="http://me.content";>
    <Item>
      <Ref>1234</Ref>
      <Info desc="A widget">
        <Note>min qty 5</Note>
      </Info>
      <Quantity>10</Quantity>
    </Item>
    <!-- etc. -->
</Message>

      note the change in namespace (fictitious URIs for simplicity)

Source is:

<?xml version="1.0"?>
<report>
      <title>My Document</title>
      <origin>someone</origin>
      <form>
              <code>1234</code>
              <description note="min qty 5">A widget</description>
              <qty>10</qty>
      </form>
      <form>
              <code>99999</code>
              <description note="add 
comment">Miscellaneous</description>
              <qty>3</qty>
      </form>
</report>

And stylesheet is:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
    xmlns="http://me.envelope";
    version="1.0">
  <xsl:output method="xml" indent="yes"/>
  <xsl:template match="report">
    <Message>
      <Header>
        <Title><xsl:value-of select="title"/></Title>
        <From><xsl:value-of select="origin"/></From>
      </Header>
      <Body xmlns="http://me.content";>
        <xsl:for-each select="form">
          <Item>
            <Ref><xsl:value-of select="code"/></Ref>
            <xsl:element name="Info">
              <xsl:attribute name="desc">
                <xsl:value-of select="description"/>
              </xsl:attribute>
              <Note><xsl:value-of select="description/@note"/></Note>
            </xsl:element>
            <Quantity><xsl:value-of select="qty"/></Quantity>
          </Item>
        </xsl:for-each>
      </Body>
    </Message>
  </xsl:template>
</xsl:stylesheet>

But using libxslt (in fact xsltproc) this produces:

<?xml version="1.0"?>
<Message xmlns="http://me.envelope";>
  <Header>
    <Title>My Document</Title>
    <From>someone</From>
  </Header>
  <Body xmlns="http://me.content";>
    <Item xmlns="http://me.envelope";>
      <Ref>1234</Ref>
      <Info xmlns="http://me.content"; desc="A widget">
        <Note xmlns="http://me.envelope";>min qty 5</Note>
      </Info>
      <Quantity>10</Quantity>
    </Item>
    <Item xmlns="http://me.envelope";>
      <Ref>99999</Ref>
      <Info xmlns="http://me.content"; desc="Miscellaneous">
        <Note xmlns="http://me.envelope";>add comment</Note>
      </Info>
      <Quantity>3</Quantity>
    </Item>
  </Body>
</Message>

      note all the xmlns attributes !

It seems to assume that literal result elements in the style 
sheet that are children of Body belong to the top-level 
default namespace, not the namespace declared on Body. It 
thus switches namespace in the output.

However, elements created by xsl:element are assumed to 
belong to the inner namespace. With a mixture of both methods 
of creating elements, the output contains a mass of namespace 
changes (all wrong).

The real application is vastly more complex than this, and 
I'm hoping to be able to use xsltproc (or a custom app using 
libxslt) without having to resort to major reconstruction of 
the stylesheet (the only way I can see to fix it so far is to 
add explicit namespaces to every element in the stylesheet :( )

It strikes me as inconsistent, but I can't find anything 
explicit in the books or docs. that says how this should 
work. Is Saxon and MSXML wrong, or is libxslt - or is it "undefined"?

Comments and suggestions much appreciated

TIA
Rick Jones


--------------------------------------------------------------
------------------------------
The statements and opinions expressed here are my own
and may not represent those of the company.
This e-mail is subject to copyright and the information in it 
is confidential. It is intended only for the named recipient. 
You are advised not to disclose the contents of this e-mail
to another person or take copies of it.
--------------------------------------------------------------
-------------------------------


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>
  • RE: Literal result element namespace differs from xsl:eleme nt namespace, Jones, Rick <=