Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 8th, 2012, 05:03 AM
Registered User
 
Join Date: Jun 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Make use of default namespaces

I am very new to XSLT. Can you share me a link or example to remove namespace prefixes in inner fragments.

Example is displaed below:

<alfa data="abc" xmlns="http://test1.com/">
<mus:beta xmlns:mus="http://test2.com">
<mus:a>1234567897</mus:a>
<mus:s>777666</mus:s>
</mus:beta>
</alfa>

I would like to have:

<alfa data="abc" xmlns="http://test1.com/">
<beta xmlns="http://test2.com">
<a>1234567897</a>
<s>777666</s>
</beta>
</alfa>

Cheers!
 
Old June 8th, 2012, 05:46 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Code:
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:mus="http://test2.com"
  exclude-result-prefixes="mus"
  version="1.0">

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

<xsl:template match="mus:*">
  <xsl:element name="{local-name()}" namespace="namespace-uri()}">
     <xsl:apply-templates select="@* | node()"/>
  </xsl:element>
</xsl:template>

</xsl:stylesheet>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog

Last edited by Martin Honnen; June 8th, 2012 at 06:21 AM.. Reason: correcting function name to "namespace-uri" instead of "namespace-url"
 
Old June 8th, 2012, 09:37 AM
Registered User
 
Join Date: Jun 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Thanks; a small correction

Thanks Martin,

Your reply was a big rescue.

Let me write down the change I needed to do on my side due to a syntax error:

Code:
<?xml version='1.0'?>
<xsl:stylesheet
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:mus="http://test2.com"
        exclude-result-prefixes="mus"
        version="1.0">

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

    <xsl:template match="mus:*">
        <xsl:element name="{local-name()}" namespace="{namespace-uri(.)}">
            <xsl:apply-templates select="@* | node()"/>
        </xsl:element>
    </xsl:template>

</xsl:stylesheet>
note the {namespace-uri(.)} (the dot and { symbol.

Thanks again!

Also for Java developert: Xalan does make a bad transformation with this xsl; however saxon is ok.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Default and blank namespaces SAMiller XSLT 2 May 1st, 2007 09:56 AM
make html button default sansircar ASP.NET 1.0 and 1.1 Professional 1 October 23rd, 2006 04:25 PM
Make a image button as default submit button toshi ASP.NET 1.0 and 1.1 Basics 1 June 1st, 2006 05:25 AM
make DW 2004 my default editor for ASP/JavaScript crmpicco Dreamweaver (all versions) 2 October 24th, 2005 11:40 AM
Make the default value change marcin2k Access VBA 0 February 21st, 2005 05:22 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.