cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Conal Tuohy" <>
Subject RE: XSLT and Namespaces Problem
Date Wed, 12 Nov 2003 02:22:18 GMT
Hi Damon

I wouldn't have thought it would be necessary to declare the xmlns in the XSLT, unless you
had templates that had to refer explicitly to that namespace (that's what I was wondering
- that you might have accidentally left off the namespace declaration there). 

But your identity template matches the nodes in any namespace, using "*", so it shouldn't
be necessary to declare it. I don't know. But you could try declaring the namespace in the
stylesheet anyway ... it might help.

My guess is that the problem occurs because of <xsl:attribute name="{name()}"/> - presumably
name()="xsi:type" - but the xsi prefix is not bound to any uri! 

I suggest you just use <xsl:copy/> to copy the elements and attributes, rather than
<xsl:element name="{name()}"/> and <xsl:attribute name="{name()}"/>. That should
do it, and I believe xsl:copy will automatically copy the namespaces in scope as well. Alternatively,
you could try copying namespaces explicitly too (using the XPath namespace axis).

Good luck!


-----Original Message-----
From: Damon van Opdorp []
Sent: Wednesday, 12 November 2003 3:01 p.m.
Subject: RE: XSLT and Namespaces Problem

Hi Con,

Below is my XSLT. It throws away some nodes based on their attributes and removes some attributes
based on name. I haven't declared the xmlns in the XLST. Is it necessary to?

<?xml version="1.0"?>

<xsl:stylesheet version="1.0" xmlns:xsl="">

<!-- Match document root. -->
<xsl:template match="/" >
<xsl:apply-templates />

<!-- Swallow resource-bundle-name elements -->
<xsl:template match="resource-bundle-name" />

<!-- An identity-style matcher that 
- swallows elements which have an empty-object="true" attribute 
- suppresses the empty-object attribute
- suppresses the object-identifier attribute
<xsl:template match="*" >
<!-- Process  -->
<xsl:if test="not(@empty-object='true')" > 
<xsl:element name="{name()}" >
<xsl:for-each select="@*">
<xsl:if test="(not(name()='empty-object') and not(name()='object-identifier'))" >
<xsl:attribute name="{name()}" >
<xsl:value-of select="." />
<xsl:apply-templates />


On Thu, 2003-11-13 at 03:46, Conal Tuohy wrote: 
Hi Damon

Is the xmlns declared in the XSLT too? What does the XSLT look like?


-----Original Message-----
From: Damon van Opdorp []
Sent: Wednesday, 12 November 2003 2:43 p.m.
Subject: XSLT and Namespaces Problem

Hi all,

I've having a problem getting XSLT transforms to work where there are namespaces used in my
xml.  Here is a snippet of the XML going into the transform:

<unit-sale-prices xmlns:xsi="" list-item="false"
empty-object="false" large-item="true" xsi:type="java:com.deeperdesign.marketplace.entity.unit.UnitSalePrice"
> ...

I'm using the default Xalan based transformer and it's complaining to the log files with the
following message:

javax.xml.transform.TransformerException: Could not resolve namespace prefix: xsi. The node
will be ignored.
at org.apache.xalan.transformer.MsgMgr.warn(
at org.apache.xalan.transformer.MsgMgr.warn(
at org.apache.xalan.templates.ElemElement.execute(
at org.apache.xalan.templates.ElemAttribute.execute(
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(

As far as I can see, the xsi namespace is defined, but for some reason my XSLT processor isn't
noticing the declaration.  The xml is castor generated, it's using the xsi namespace so that
it can record the type of the objects to make it possible to turn the xml back into java objects.
 I'm using Cocoon 2.1.1 with Tomcat 4.1.29.  My Xalan version is 2.5.1.

Any suggestions welcome :)


Damon-- Damon van Opdorp » Systems Architect » » +64(21)
23 94 328Deeper Design Limited » +64(7) 377 3328 » 

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message