xsl-list
[Top] [All Lists]

Re: [xsl] [XSLT 1.0] Replace namespace prefixes?

2009-12-24 12:19:35
Hi Roger,
  I found the solutions presented below, to work.

On Thu, Dec 24, 2009 at 10:09 PM, Costello, Roger L. 
<costello(_at_)mitre(_dot_)org> wrote:
Into this:

   <bk:book xmlns:bk="http://www.book.org";>
       <bk:title>The Origin of Wealth</bk:title>
       <bk:author>Eric D. Beinhocker</bk:author>
       <bk:date>2006</bk:date>
       <bk:ISBN>1-57851-777-X</bk:ISBN>
       <bk:publisher>Harvard Business School Press</bk:publisher>
       <bk:cost currency="USD">29.95</bk:cost>
   </bk:book>

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

   <xsl:output method="xml" />

   <xsl:template match="node() | @*">
     <xsl:copy>
       <xsl:apply-templates select="node() | @*" />
     </xsl:copy>
   </xsl:template>

   <xsl:template match="/">
     <xsl:element name="bk:{local-name(*)}" xmlns:bk="http://www.book.org";>
       <xsl:copy-of select="*/@*" />
       <xsl:apply-templates select="*/node()" />
     </xsl:element>
   </xsl:template>

   <xsl:template match="*">
     <xsl:element name="bk:{local-name()}">
       <xsl:copy-of select="@*" />
       <xsl:apply-templates />
     </xsl:element>
   </xsl:template>

</xsl:stylesheet>

Or this:

   <book xmlns="http://www.book.org";>
       <title>The Origin of Wealth</title>
       <author>Eric D. Beinhocker</author>
       <date>2006</date>
       <ISBN>1-57851-777-X</ISBN>
       <publisher>Harvard Business School Press</publisher>
       <cost currency="USD">29.95</cost>
   </book>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                       xmlns="http://www.book.org";
                       exclude-result-prefixes=""
                       version="1.0">

   <xsl:output method="xml" />

   <xsl:template match="node() | @*">
     <xsl:copy>
       <xsl:apply-templates select="node() | @*" />
     </xsl:copy>
   </xsl:template>

   <xsl:template match="/">
     <xsl:element name="{local-name(*)}" xmlns="http://www.book.org";>
       <xsl:copy-of select="*/@*" />
       <xsl:apply-templates select="*/node()" />
     </xsl:element>
   </xsl:template>

   <xsl:template match="*">
     <xsl:element name="{local-name()}">
       <xsl:copy-of select="@*" />
       <xsl:apply-templates />
     </xsl:element>
   </xsl:template>

</xsl:stylesheet>


-- 
Regards,
Mukul Gandhi

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