You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Nathan Pride <np...@wavo.com> on 2000/01/31 20:40:49 UTC
Consecutive XSLT transformations
Hi All,
A little history:
This is a progression from how to include other xml documents in
a new document without using the ENTITY property. After upgrading to
Cocoon 1.6.1 and the new XSLT processors I now have some success BUT ...
The problem:
After the first XSLT transformation generating the new xml
document I don't know how to include the further processing
instructions.
This is what I want
XML --> [XSLT] --> XML --> [XSLT] --> HTML
Here's how I'm trying to do it:.
File: page.xml
<?xml version="1.0"?>
<?xml-stylesheet href="stage1.xsl" type="text/xsl"?>
<?cocoon-process type="xslt"?>
<files>
<external href="include1.xml"/>
<external href="include2.xml"/>
</files>
File: include1.xml
<?xml version="1.0"?>
<message>
<text>Hello world type of text</text>
Blah blah blah.
</message>
File: include2.xml
<?xml version="1.0"?>
<message>
<text>This is the other external file</text>
Blah blah blah.
</message>
File: stage1.xsl
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform/1.0">
<xsl:template match="external">
<xsl:comment>Here are the contents of "external" URI <xsl:value-of
select="@href"/></xsl:comment>
<other_file>
<xsl:copy-of select="document(@href)"/>
</other_file>
</xsl:template>
<xsl:template match="/">
<document>
<xsl:apply-templates/>
</document>
</xsl:template>
</xsl:stylesheet>
Which gives the result:
<?xml version="1.0" encoding="UTF-8"?>
<document>
<!--Here are the contents of "external" URI include1.xml-->
<other_file>
<message>
<text>Hello world type of text</text>
Blah blah blah.
</message>
</other_file>
<!--Here are the contents of "external" URI include2.xml-->
<other_file>
<message>
<text>This is the other external file</text>
Blah blah blah.
</message>
</other_file>
</document>
Great, however I would like to transform the result by using the
following:
File: stage2.xsl
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform/1.0">
<xsl:template match="/">
<xsl:processing-instruction
name="cocoon-format">type="text/html"</xsl:processing-instruction>
<html>
<head>
<title>Consecutive XSLT processing example.</title>
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="message">
<table bgcolor="yellow" border="1">
<tr>
<td>
<xsl:apply-templates/>
</td>
</tr>
</table>
<p/>
</xsl:template>
<xsl:template match="text">
<font color="blue"><xsl:apply-templates/></font>
</xsl:template>
</xsl:stylesheet>
Now to do this I believe I need the following lines to be generated
within the first result:
<?xml version="1.0" encoding="UTF-8"?> <!-- already there
-->
<?xml-stylesheet href="stage2.xsl" type="text/xsl"?> <!-- new -->
<?cocoon-process type="xslt"?> <!-- new -->
<document>
.... etc.
to do that I thought the following lines would be required in stage1.xsl
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform/1.0">
<xsl:template match="external">
<xsl:comment>Here are the contents of "external" URI <xsl:value-of
select="@href"/></xsl:comment>
<other_file>
<xsl:copy-of select="document(@href)"/>
</other_file>
</xsl:template>
<xsl:template match="/">
<!-- ***** New code **** -->
<xsl:processing-instruction type="xml-stylesheet">
href="stage2.xsl" type="text/xsl"
</xsl:processing-instruction>
<xsl:processing-instruction type="cocoon-process">
type="xslt"
</xsl:processing-instruction>
<!-- ***** /New code **** -->
<document>
<xsl:apply-templates/>
</document>
</xsl:template>
</xsl:stylesheet>
However when I try to do this I get the following error from Cocoon
"Error found handling the request" with the following stack trace:
at org.apache.xalan.xslt.XSLTEngineImpl.error(XSLTEngineImpl.java:1487)
at org.apache.xalan.xslt.XSLTEngineImpl.error(XSLTEngineImpl.java:1396)
at org.apache.xalan.xslt.ElemPI.(ElemPI.java, Compiled Code)
at
org.apache.xalan.xslt.StylesheetHandler.startElement(StylesheetHandler.java,
Compiled Code)
at org.apache.xalan.xpath.xml.TreeWalker.startNode(TreeWalker.java,
Compiled Code)
at org.apache.xalan.xpath.xml.TreeWalker.traverse(TreeWalker.java,
Compiled Code)
at
org.apache.xalan.xslt.XSLTEngineImpl.processStylesheet(XSLTEngineImpl.java:658)
at org.apache.xalan.xslt.XSLTEngineImpl.process(XSLTEngineImpl.java,
Compiled Code)
at
org.apache.cocoon.transformer.XalanTransformer.transform(XalanTransformer.java:94)
at
org.apache.cocoon.processor.xslt.XSLTProcessor.process(XSLTProcessor.java:103)
at org.apache.cocoon.Engine.handle(Engine.java, Compiled Code)
at org.apache.cocoon.Cocoon.service(Cocoon.java:145)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:588)
at
org.apache.jserv.JServConnection.processRequest(JServConnection.java:314)
at org.apache.jserv.JServConnection.run(JServConnection.java:188)
at java.lang.Thread.run(Thread.java:479)
Just for the record;
Running on NT
Apache 1.3.9
Cocoon 1.6.1
Xerces 0.19.2
Xalan 1.0.1
Thanks in advance
Nathan