From TEIWiki

Jump to: navigation, search



This is a quick XSLT script for removing the namespaces from any document. It will remove the prefix as well. I think I picked it up off the XSL-List run by mulberry-tech. This is sometimes a good first step to remove namespaces from a set of files some of which use namespaces and some of which don't.

Add any comments to the 'discussion' tab.

Required Input

This document will take any XML file, not just TEI XML, and remove a namespace from it if it exists. If there are entities in the document, these will naturally be expanded.

Expected Output

Same document, but with the namespaces and namespace prefix removed.

Known Restrictions or Problems

Obviously, if you need the namespaces then this might not be as useful to you.  For example, where 

you have documents which use elements from different namespaces with the exact same local-name (for example, TEI's <title> and HTML's <title> then flattening the document to remove namespaces would be problematic.


<xsl:stylesheet version="1.0" xmlns:xsl="">
<xsl:output method="xml" indent="no"/>

<xsl:template match="/|comment()|processing-instruction()">

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

<xsl:template match="@*">
    <xsl:attribute name="{local-name()}">
      <xsl:value-of select="."/>
Personal tools