cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Conal Tuohy" <Conal.Tu...@vuw.ac.nz>
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!

Con

-----Original Message-----
From: Damon van Opdorp [mailto:damon.vanopdorp@deeperdesign.co.nz]
Sent: Wednesday, 12 November 2003 3:01 p.m.
To: users@cocoon.apache.org
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="http://www.w3.org/1999/XSL/Transform">

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

<!-- 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:attribute>
</xsl:if>
</xsl:for-each>
<xsl:apply-templates />
</xsl:element>
</xsl:if>
</xsl:template>

</xsl:stylesheet>

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?

Con

-----Original Message-----
From: Damon van Opdorp [mailto:damon.vanopdorp@deeperdesign.co.nz]
Sent: Wednesday, 12 November 2003 2:43 p.m.
To: users@cocoon.apache.org
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="http://www.w3.org/2001/XMLSchema-instance" 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(MsgMgr.java:187)
at org.apache.xalan.transformer.MsgMgr.warn(MsgMgr.java:144)
at org.apache.xalan.templates.ElemElement.execute(ElemElement.java:344)
at org.apache.xalan.templates.ElemAttribute.execute(ElemAttribute.java:144)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2318)
...

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 :)

Cheers,

Damon-- Damon van Opdorp » Systems Architect » damon.vanopdorp@deeperdesign.com » +64(21)
23 94 328Deeper Design Limited » +64(7) 377 3328 » www.deeperdesign.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message