This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

stripping useless xmlns?


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]