xsl-list
[Top] [All Lists]

Re: [xsl] Getting the root namespace from the input document

2007-02-05 09:12:39
On 2/5/07, Mukul Gandhi <gandhi(_dot_)mukul(_at_)gmail(_dot_)com> wrote:
On 2/5/07, Andrew Welch <andrew(_dot_)j(_dot_)welch(_at_)gmail(_dot_)com> wrote:
> <xsl:template match="/">
>        <Metadata>
>                <xsl:copy-of select="namespace::node()"/>
>        </Metadata>
> </xsl:template>

I think Andrew means:

<xsl:template match="/manifest">
   <Metadata>
      <xsl:copy-of select="namespace::*"/>
   </Metadata>
</xsl:template>

I did, well spotted!

But namespace:: axis is deprecated in XSLT 2.0 (though, Saxon supports it)

That's interesting... wasn't aware of that.

If you are using XSLT 2.0, the following is perhaps a portable way:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="2.0">

<xsl:output method="xml" indent="yes" />

<xsl:template match="manifest">
  <xsl:variable name="x" select="." />
  <Metadata>
    <!-- create namespace declarations -->
    <xsl:for-each select="in-scope-prefixes($x)">
      <xsl:namespace name="{.}"><xsl:value-of
select="namespace-uri-for-prefix(., $x)" /></xsl:namespace>
    </xsl:for-each>

    <!-- do rest of things -->
  </Metadata>
</xsl:template>

</xsl:stylesheet>

That's really cool too.  This is all news to me - I didn't think the
prefixes were available to the XSLT processor...?

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