xsl-list
[Top] [All Lists]

Re: [xsl] strip-spaces

2008-02-06 03:18:22
On 05/02/2008, Michael Kay <mike(_at_)saxonica(_dot_)com> wrote:
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">


Another example which might help (and help confirm it in my own mind):

<xsl:template match="/">
    <parent xmlns="foo">
      <xsl:apply-templates/>    
    </parent>
</xsl:template>

<xsl:template match="child">
        <child/>        
</xsl:template>

you expect the output to be:

<parent xmlns="foo">
  <child/>
</parent>

but instead the output is:

<parent xmlns="foo">
  <child xmlns=""/>
</parent>

and you want to get rid of the xmlns="" on <child>...

The reason why it's there is because <child> is in no namespace, and
the reason it is in no namespace is because in the stylesheet:

<xsl:template match="/">
  <parent xmlns="foo">
    <xsl:apply-templates/>      
  </parent>
</xsl:template>

<xsl:template match="child">
  <child/>      
</xsl:template>

...<child> is in a different scope to <parent> (even though in your
mind <parent> contains <child>) - you have to see the XSLT as XML to
know which namespace child will be in, and looking at it like that its
clear that <child> is not a descendant or <parent> and not covered by
its xmlns declaration.

The solution is to put <child> in the namespace in the
XML-that-is-the-stylesheet, which can be done by declaring the
namespace on the element itself, or by moving the namespace
declaration to common ancestor - like the root element xsl:stylesheet

Is that an accurate view of whats going on?



-- 
Andrew Welch
http://andrewjwelch.com
Kernow: http://kernowforsaxon.sf.net/

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>