RE: [xsl] strip-spaces

Subject: RE: [xsl] strip-spaces
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 5 Feb 2008 18:05:16 -0000
> Having done that I note that an xmlns tag is now on some 
> nodes and not on others.
> 
> 	1. why has the serializer placed these tags on any node 
> (for example, some <p> node and not others)?

The serializer will add an xmlns="" namespace declaration to any element if
(a) that element has a name in no namespace, and (b) its parent has a name
that is in a specific namespace.

> 	2. how can I get rid of them (globally specify the 
> namespace) because these tags significantly increase the file size?

File size is immaterial. You need to get rid of them because your elements
have the wrong names, which is much more important. The way you get rid of
them is to generate elements that have the right names in the first place,
always remembering that an element name is in two parts: the local part and
the namespace URI.
> 
> I assume the fact that the serializer has been selective 
> tells me something about the way I've written the template - 
> what have I done wrong?

I haven't followed this thread closely, I thought a lot of people had been
telling you what you did wrong. The most common reason is doing something
like

<xsl:template match="parent">
  <div xmlns="namespace1">
    <xsl:apply-templates select="child"/>
  </div>
</xsl:template>

<xsl:template match="parent">
  <p>
    <xsl:apply-templates select="child"/>
  </p>
</xsl:template>

and the fix is to generate the <p> element in the same namespace as its
parent, which can be achieved using

<p xmlns="namespace1">

Michael Kay
http://www.saxonica.com/

Current Thread