Re: [xsl] Unwanted Prefixes in Output

Subject: Re: [xsl] Unwanted Prefixes in Output
From: Alan <alan-xsl-list@xxxxxxxxx>
Date: Thu, 22 Sep 2005 17:17:03 -0400
* Michael Kay <mike@xxxxxxxxxxxx> [2005-09-21 07:19]:
> > -----Original Message-----
> > From: Alan [mailto:alan-xsl-list@xxxxxxxxx] 
> > Sent: 21 September 2005 10:32
> > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > Subject: Re: [xsl] Unwanted Prefixes in Output
> > 
> > * Alan <alan-xsl-list@xxxxxxxxx> [2005-09-21 04:30]:
> > > * Alan <alan-xsl-list@xxxxxxxxx> [2005-09-21 04:24]:
> > > >     Probably common problem with namespace emissions. Tried to cut
> > > >     it down to the basics.
> > > 
> > > > I'd like to omit "xmlns:foo" namespace declaration where 
> > it will not
> > > > be referenced, like under atom:updated.
> > > 
> > >     Should note that the saved documents can contain any namespace,
> > >     so I can't add xmlns:foo declaration to my stylesheet, but I'd
> > >     like to have my namespaces namespace normal.
> > > 
> > >     http://www.flightlab.com/~joe/sgml/sanity.txt
> > > 
> > >     Cheers.
> > 
> >     I'm talking to myself now. :^)
> > 
> >     I found that this removes unnecessary namespace declarations...
> > 
> >       <xsl:template match="atom:*" mode="copy-entry">
> >         <xsl:element name="atom:{local-name(.)}">
> >           <xsl:copy-of select="@*"/>
> >           <xsl:apply-templates select="node()" mode="copy-entry"/>
> >         </xsl:element>
> >       </xsl:template>
> > 
> >     And the "xmlns:foo" only appears on "foo" namespace elements.
> > 
> >     This is pretty close to "namespace normal".
> > 
> >     Can it get any better?

> In XSLT 2.0 you could replace
> 
> <xsl:element name="atom:{local-name(.)}">

> with

> <xsl:copy copy-namespaces="no">

    I'll try this. (And in response to your other comment, sorry for
    mangling my example.)

> When you say "can it get any better", do you mean you want "better" output,
> or you want a better way of producing the output you are now getting?

    Better meaning "namespace normal". I've removed extra namespace
    declaration where they are redundant, which makes the documents
    much easier to read.

    As was noted in another post, a two stage transformation is
    probably necessary to get "namespace normal", and this code,
    removing unnecessary namespaces, is the first stage.

    Thank you.

--
Alan Gutierrez - alan@xxxxxxxxx
   - http://engrm.com/blogometer/index.html
   - http://engrm.com/blogometer/rss.2.0.xml

Current Thread