Search
Web Braintrove
Site Navigation
Home
Products
Tags
Levels
Dates
Authors
5 MOST RECENT
Create Shared Rules
Perform a Case-Insensitive String Comparison without Using Translate()
Force a Field Value to a Boolean Using Rules
Quickly Crop to a Shadow
Sum Repeating Time Values
5 MOST POPULAR
Pass Query String Parameters to an ASP.NET Xml Control
Access a Method in a Master Page with Code-Behind
Prevent Namespace Prefixes from Being Copied to the Output
Create Groups in a Drop-Down List Box
Change the Default Action of the Power Button on the Windows Vista Start Menu
5 MOST FORGOTTEN
Install Windows 7 Beta onto a Virtual Machine
Configure Lab Color Mode Defaults for Braintrove Articles
Permanently Change the Default Styles for New Word Documents
Enable Themes in Windows Server
Conditionally Display the Singular or Plural Form of Words
Books
Web Standards Programmer's Reference : HTML, CSS, JavaScript, Perl, Python, and PHP
XPath 2.0 Programmer's Reference
XSLT Quickly
HTML for Dummies
creative html design.2
Magazines
SQL Server Magazine
Soa Web Services Journal
Inside Visual Basic
Asp.netpro
Visual Basic & Net Journal
Microsoft MVP
Very PopularMost Viewed
This article has been viewed 10090 times.

Prevent Namespace Prefixes from Being Copied to the Output

Written by Gregory Scot Collins
Tuesday, 2 May 2006, 10:02 AM
This article has been tested to work with the following products and versions. No guarantee of compatibility, with or without modification, is offered for products or versions other than those listed.
Any namespace prefix specified on the xsl:stylesheet element is automatically copied to your output. If, for example, your XSLT employs JavaScript code, the specified namespace prefix required to call the JavaScript functions will be copied to your output. Let's create some test files to demonstrate the issue and the solution.

Create the source files

We need a simple XML file to transform. Copy the contents of Listing 1 into a text editor, and then save the file as Test.xml.
Copy the contents of Listing 2 into a text editor, and then save the file as Test.xsl. Be sure to save it in the same folder the as Test.xml file.
Applying the transform to our XML results in the following output:
<html xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:js="JavaScript">
    <head>
        <title>BRAINTROVE</title>
    </head>
    <body>visit http://www.braintrove.com</body>
</html>
In many situations the additional namespace prefixes will not pose a problem; however, you might prefer to have them not present. This is easily fixed.

Update the XSLT to exclude specific namespace prefixes from the output

You can prevent specific namespace prefixes from being copied to your output by using the optional exclude-result-prefixes attribute on the xsl:stylesheet element. Use a whitespace separator between each prefix you want excluded from your output.
Listing 3 shows the addition of the exclude-result-prefixes attribute, highlighted in green:
Applying the updated transform to our XML results in the following output that correctly excludes the additional namespace prefixes:
<html>
    <head>
        <title>BRAINTROVE</title>
    </head>
    <body>visit http://www.braintrove.com</body>
</html>
Bookmark this Article
StumbleUpon  Stumble It!
Digg  Digg It!
del.icio.us  del.icio.us
List of Figures
Listing 1 - The Test.xml file.
Listing 2 - The Test.xsl file.
Listing 3 - The updated Test.xsl file excludes the specified namespaces from the output.
Article Tags
Great Deals
TigerDirect Exclusive Deals, Limited Time Offers, Act Now And Save!
Find all current special offers on Adobe products.
Try SugarSync Free!
Join WebHost4Life.com
TigerDirect
Computers4SURE (4SURE.com - An Office Depot Co.)
Copyright © 2006-2010 Braintrove. All rights reserved. Braintrove, braintrove.com, and the Braintrove logo are trademarks of Gregory Scot Collins in the United States and/or other countries. The names of actual companies and products mentioned herein may be the trademarks of their respective owners. Any rights not expressly granted herein are reserved.