Search
Web Braintrove
Site Navigation
Home
Products
Tags
Levels
Dates
Authors
5 MOST RECENT
Locate the Design Checker Task Pane in InfoPath 2010
Locate Conditional Formatting and Custom Validation in InfoPath 2010
Conditionally Display Different Values In a Single Expression Box
Create a Button With a Blank Label
Create Shared Rules
5 MOST POPULAR
Access a Method in a Master Page with Code-Behind
Pass Query String Parameters to an ASP.NET Xml Control
Prevent Namespace Prefixes from Being Copied to the Output
Create Groups in a Drop-Down List Box
Configure IIS 7 for Custom Error Pages
5 MOST FORGOTTEN
Install Windows 7 Beta onto a Virtual Machine
Group Dates by Year, Month and Day
Configure Lab Color Mode Defaults for Braintrove Articles
Create a Monochromatic Dream Text Effect Using Styles
Combine Multiple Sums Into a Single Function
Books
Easy HTML-DB Oracle Application Express : Create Dynamic Web Pages with OAE
Learn HTML 4 In a Weekend
HTML for Dummies
HTML: Your visual blueprint for designing effective Web pages with HTML, CSS, and XHTML
Beginning XSLT
Magazines
Web Site Management And Internet Advertising Trends
MSDN Magazine
Visual Studio Magazine
Inside Visual Basic
Inside Web Development
Microsoft MVP
Very PopularMost Viewed
This article has been viewed 11513 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.