[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

stripping useless xmlns?

Subject: stripping useless xmlns?
From: "Mark D. Anderson" <mda@xxxxxxxxxxxxxx>
Date: Fri, 3 Mar 2000 19:58:14 -0800
test for null xsl
due to spotty support for exclude-result-prefixes and/or the fact that the spec
seems to allow putting pretty much any namespace nodes it likes for xsl:element,
my generated instances keep getting all these xmlns:some-unused-prefix="whatever" nodes
all over the place.

doesn't hurt anything, it just bothers me.

so how hard would it be write a post-processing stylesheet that stripped out all
xmlns nodes for prefixes that aren't used?

i think it would go something like this, except this gets "unexpected node test" on the namespace
match, and i'm sure there are other bugs too....

-mda

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

  <!-- collect up all prefixes used -->
  <xsl:variable name="used_prefixes" select="substring-before(name(//*), ':')"/>

  <!-- match all namespace nodes -->
  <xsl:template match="namespace::*" priority="99">
    <xsl:if test="$used_prefixes = substring-after(name(.),':')">
      <xsl:copy/>
    </xsl:if>
  </xsl:template>

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




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.