default namespace in xsl

Here should go questions about transforming XML with XSLT and FOP.
miky
Posts: 1
Joined: Wed May 31, 2006 4:15 pm

default namespace in xsl

Post by miky »

I receive an xml message with the following format:

Code: Select all

<?xml version="1.0" encoding="ISO-8859-1" ?> 
<staticMessage xmlns="Static/nme" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="Static/nme ./StaticMessage.xsd">
...
</staticMessage>
I fail to apply transformation when using a stylesheet like:

Code: Select all

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:value-of select="staticMessage/body/data"/>
</xsl:template>
</xsl:stylesheet>
I have tried adding the default namespace to the xsl (xmlns="Static/nme" ) without sucess.
However if I use a prefix xmlns:j="Static/nme" , I can reference my nodes with j:\

Is this a normal behavior and is there a way of using the default namespace in the xsl sheet to reference nodes and values?

Tx,
Mik.
george
Site Admin
Posts: 2097
Joined: Thu Jan 09, 2003 2:58 pm

Post by george »

Hi Mik,

Yes, this is the expected behavior, name tests without prefix in Path 1.0 are in no namespace, if you want a name test in some namespace you need to use a prefix.
XPath 2.0 allows specifying a default namespace for name tests and you can do that in a stylesheet with the xpath-default-namespace attribute.

Best Regards,
George
Post Reply