xsl-list
[Top] [All Lists]

Re: Unwanted Prefixes in Output

2005-09-21 03:15:22
* Robert Koberg <rob(_at_)koberg(_dot_)com> [2005-09-21 05:48]:
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?

    Not quite.
    
    Unknown elements in the Atom namespace make the document invalid
    Atom.

    Atom allows stuff from other namespaces, that's how you extend it.

    I'm aggregating, creating new Atom feeds from different sources.
    I've saved the entries in files. Some of the entries have
    unpredictable extention namespaces.

    Ideal output...

    <atom:entry atom:xmlns="http://www.w3.org/2005/Atom";
                xmlns:sw="tag:somewhere.com,2005:/extra">
      <atom:id>tag:somewhere.com,2005:/feed/article</atom:id>
      <atom:link
        rel="alternate"
        href="http://somewhere.com/feed/article</atom:link>
      <sw:extra-info>I like cheese!</sw:extra-info>
      <atom:updated>2005-09-20T20:32:10Z</atom:updated>
    </atom:entry>

    Where I'm at now...

    <atom:entry atom:xmlns="http://www.w3.org/2005/Atom";>
      <atom:id>tag:somewhere.com,2005:/feed/article</atom:id>
      <atom:link
        rel="alternate"
        href="http://somewhere.com/feed/article</atom:link>
      <sw:extra-info xmlns:sw="tag:somewhere.com,2005:/extra">I like 
cheese!</sw:extra-info>
      <atom:updated>2005-09-20T20:32:10Z</atom:updated>
    </atom:entry>

    The fix in the last post made it like the above.

    Where I was...

    <atom:entry atom:xmlns="http://www.w3.org/2005/Atom";>
      <atom:id 
xmlns:sw="tag:somewhere.com,2005:/extra">tag:somewhere.com,2005:/feed/article</atom:id>
      <atom:link
        xmlns:sw="tag:somewhere.com,2005:/extra"
        rel="alternate"
        href="http://somewhere.com/feed/article</atom:link>
      <sw:extra-info xmlns:sw="tag:somewhere.com,2005:/extra">I like 
cheese!</sw:extra-info>
      <atom:updated 
xmlns:sw="tag:somewhere.com,2005:/extra">2005-09-20T20:32:10Z</atom:updated>
    </atom:entry>

    So, I'm happier, but the first version would be "namespace
    normal", and that's supposed to be ideal. 

    Cheers.

--
Alan Gutierrez - alan(_at_)engrm(_dot_)com
    - http://engrm.com/blogometer/index.html
    - http://engrm.com/blogometer/rss.2.0.xml

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