This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Q: Stripping ns from source tree?
- To: xsl-list at lists dot mulberrytech dot com
- Subject: Re: [xsl] Q: Stripping ns from source tree?
- From: Niclas Olofsson <niclas dot olofsson at ismobile dot com>
- Date: Mon, 27 Aug 2001 01:14:47 +0200
- References: <3B893E19.FB9366A7@ismobile.com> <3B895F1A.1503C716@redrice.com>
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi Francis,
Ok, looks interesting. Trying that next. Here is what I've got so far
(on my own).
I changed the namespacing in the original XML to only use default
namespaces where it did apply. I ended up with nested namspaces (mf in
html in mf .. etc) which only made it worse. So, applying a default
namespace to all elements (most of it by inheritence) made the
stylesheet work. In brief (this is not the actual stuff) it looks
something like:
<xsl:template match="html:*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates select="*"/>
</xsl:copy>
</xsl:template>
But it didn't really solve much of my original problem. So what I'll
have to do is apply your local-name() patch to it and I should be
homesafe.
Thanks,
/Niclas
Francis Norton wrote:
>
> Hi Niclas,
>
> Niclas Olofsson wrote:
> >
> > Basically my problem is that the source tree I'm using have 2 different
> > namespaces, one for html and one for my own format ("mf").
> >
> The problem is fairly simple once you understand what's going on.
>
> First thing - exclude-result-prefixes and xsl:exclude-result-prefixes
> only exclude namespace declarations for namespaces which are *unused* in
> the output. You can't use them to strip namespaces from elements or
> attributes which would otherwise have them.
>
> Your example uses namespaces in the output in two ways:
>
> [1] you've registered a default namespace for all your literal result
> HTML elements
>
> [2] you copy HTML-namespace elements in the source document
>
> So first get rid of that default xmlns="http://www.w3.org/TR/REC-html40"
> in the stylesheet - you don't need it, after all, since you want your
> result elements to be simple HTML.
>
> Next, let's match any HTML-namespace elements in the source documents
> and automatically create the equivalent element in the output, but not
> in any namespace. We'll use xsl:element for this, with the new element
> name coming from the local-name() of the original.
>
> OK, here's the stylesheet that implements these two steps, it's tested
> and works with saxon and msxsl -
>
> <?xml version="1.0"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:html="http://www.w3.org/TR/REC-html40"
> xmlns:mf="myformat"
> exclude-result-prefixes="html mf"
> >
>
> <xsl:output method="html" omit-xml-declaration="yes"/>
>
> <xsl:template match="/">
> <HTML
> >
> <BODY>
> <xsl:apply-templates/>
> </BODY>
> </HTML>
> </xsl:template>
>
> <xsl:template match="mf:*">
> <!-- do nothing right now -->
> <xsl:apply-templates/>
> </xsl:template>
>
> <xsl:template match="html:*">
> <xsl:element name="{local-name()}">
> <xsl:apply-templates/>
> </xsl:element>
> </xsl:template>
> </xsl:stylesheet>
>
> Hope this helps -
>
> Francis.
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
--
Niclas Olofsson - http://www.ismobile.com
Product Development, isMobile, Aurorum 2, S-977 75 Luleå, Sweden
Phone: +46(0)920-75550
Mobile: +46(0)70-3726404
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list