xsl-list
[Top] [All Lists]

Re: Unwanted Prefixes in Output

2005-09-21 02:47:55
Hi,

Alan wrote:

   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>

I think you want something like:


<xsl:template match="atom:*" mode="copy-entry">
<xsl:copy>
  <xsl:copy-of select="@*"/>
  <xsl:apply-templates mode="copy-entry"/>
</xsl:copy>
</xsl:template>

<xsl:template match="*" mode="copy-entry">
<xsl:element name="{local-name()}" namespace="http://the-atom-namespace";>
  <xsl:apply-templates select="@*"/>
  <xsl:apply-templates mode="copy-entry"/>
</xsl:element>
</xsl:template>

  <xsl:template match="@*">
    <xsl:attribute name="{local-name()}">
      <xsl:value-of select="."/>
    </xsl:attribute>
  </xsl:template>


This way you you can put everything in the atom namespace and just simplay copy over existiing atom namespaced elements.

is that what you are thinking?

best,
-Rob


    And the "xmlns:foo" only appears on "foo" namespace elements.

    This is pretty close to "namespace normal".

    Can it get any better?

--~------------------------------------------------------------------
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>
--~--