XSLT hacker

So far, this week has been a week of XSLT hacking. My favorite is probably the XSLT script that generates another XSLT script! 🙂

At one point I wanted to copy the default namespace (xmlns=…) from the source document to the destination document.

I did like this to retrieve the URI for the default namespace. Maybe there is a simpler way?

<xsl:variable name="uri" select="string(namespace::*[name(.) = ''])"/>

In order to set the default namespace I found the excellent Creating namespace nodes in XSLT 1.0 blog post. The most relevant part was this hack:

<xsl:attribute
  name="{ concat($prefix, ':dummy-for-xmlns') }"
  namespace="{ $uri }">
</xsl:attribute>

I’d also like to mention that Jing seems to work fine for validating an XML document against an XML schema definition (XSD).

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.