Categories
Technology

The XInclude namespace foolishness

I was going through XInclude for my project.

The project required me to use Xerces SAX parser.

My input XML document used 2003 in the XInclude namespace (http://www.w3.org/2003/XInclude). The XInclude processor in Xerces does not support 2003 namespace but only 2001 (http://www.w3.org/2001/XInclude) apparently because this namespace is no longer recognized (this document says so). So the processor was not working as I felt it would. I tried hard the whole day trying to find a solution and did a lot of silly things (You would expect anyone to do silly things in case they don't get a solution for a long time when they expect the solution to be simple). Finally I tumbled across this FAQ and lo, it said all!!!

Here's what the recommendation says:

Please note that the namespace URI has been reverted back to the URI found in earlier drafts of XInclude. This document defines the namespace URI http://www.w3.org/2001/XInclude; the http://www.w3.org/2003/XInclude namespace URI found in the Last Call is made obsolete by this document.

Too late to realize? 🙁

Categories
World Wide Web

The default namespace problem in XSLT 1.0

(This blog is only for my reference. Non-XSLT users please dis-regard
this blog entry. XSLT users please suggest some alternatives/comments.)

There is a problem popularly called the default namespace problem in
XSLT 1.0. Supposedly this problem has been solved in the newer version
of XSLT (XSLT 2.0).

The problem is not discussed here, rather the solution is given below:

Consider an input XML file bound to a default namespace:

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="new.xsl"?>
<catalog xmlns="http://buzypi.50webs.com/">
 <entry>1</entry>
 <entry>2</entry>
 <entry>3</entry>
</catalog>


Consider the XSLT style-sheet:

<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:my="http://buzypi.50webs.com/"
>

<xsl:template match="/">
 <html>
 <body>
  <xsl:apply-templates select="my:catalog/my:entry" />
 </body>
 </html>
</xsl:template>

<xsl:template match="my:entry">
 <h1><xsl:value-of select="." /></h1>
</xsl:template>

</xsl:stylesheet>

The problem is thus solved by defining our own namespace and using it to refer to all default namespace elements.

There is another solution using local-name() function of XPath (Please refer to biglist link below for that solution).

XSLT 2.0 has something called default-xpath-namespace, which is used to solve the problem.

This thread on biglist deals with the default namespace problem.