Hi,
I have been having a great deal of difficulty transforming a
org.w3c.dom.Document object with the xtags:style (and also x:transform) tag.
All the examples have been targetted toward reading XML from a file ( url
and StreamSource approaches). However, in our application we need to
receive data from the business layer as an XML org.w3c.dom.Document object -
I don't want to transform the Document object into a String object before
trying the transformation.
Here's the test code I've been using with what does and what doesn't seem to
work:
<%@page language="java" session="true"%>
<html>
<body>
<%@ taglib uri="examples-taglib" prefix="eg" %>
<%@ taglib uri="jakarta-import-taglib" prefix="c" %>
<%@ taglib uri="xtags-taglib" prefix="xtags" %>
<%@ taglib uri="x-transform-taglib" prefix="x" %>
<b><u>Resource description: </u></b>
<!-- Trial XSLT -->
<!-- FORM tags always needed otherwise input will not show in Netscape 4.75
-->
<form>
<%! javax.xml.transform.Source source; %>
<%! java.lang.String uriXSL; %>
<%
String uriXML =
"file:///D:/development/tools/jakarta-tomcat-4.0.1" +
"/webapps/proto/jsp/test.xml";
uriXSL =
"file:///D:development/tools/jakarta-tomcat-4.0.1" +
"/webapps/proto/jsp/test.xsl";
source = new javax.xml.transform.stream.StreamSource(uriXML);
%>
<!-- this works Fine-->
<xtags:style xsl="<%= uriXSL %>" xmlSource="<%= source %>"/>
<!-- now test as DOM object -->
<%! javax.xml.transform.dom.DOMSource domSource; %>
<!-- this bean simply creates a full textual xml presentation of the DOM
tree -->
<!-- it works fine -->
<jsp:useBean id="testDomProcessor"
class="com.tietoenator.domutils.TestDomProcessor"/>
<%
//
// Create a DOM tree for this test (in practice this would be an object
in the session)
//
// Instantiate DocumentBuilderFactory.
javax.xml.parsers.DocumentBuilderFactory dfactory =
javax.xml.parsers.DocumentBuilderFactory.newInstance();
// Use DocumentBuilderFactory to access a DocumentBuilder.
javax.xml.parsers.DocumentBuilder dBuilder =
dfactory.newDocumentBuilder();
// Use DocumentBuilder to parse XML input.
org.w3c.dom.Document doc =
dBuilder.parse(uriXML);
//Now create a textual representation of the DOM tree
StringBuffer buf = new StringBuffer();
org.w3c.dom.Element root = doc.getDocumentElement();
testDomProcessor.stepThroughAll(buf, root);
%>
<!-- this works fine also -->
<xtags:style xsl="<%= uriXSL %>">
<%= buf.toString() %>
</xtags:style>
<!-- this DOESN'T work - DOMSource content is empty -->
<% domSource = new javax.xml.transform.dom.DOMSource(doc); %>
<xtags:style xsl="<%= uriXSL %>" xmlSource="<%= domSource %>"/>
<!-- x taglibs used - this works for static resources and doesn't handle
DOM tree -->
<c:import url="test.xml" var="xml"/>
<c:import url="test.xsl" var="xslt"/>
<x:transform source="$xml" xslt="$xslt"/>
</form>
</body>
</html>
Anyone got any ideas how to get xtags:style and x:transform to work with a
org.w3c.dom.Document object?
Many thanks in advance,
- Peter
*********************************************
Peter Burgess
Technical Architect
TietoEnator (Belgium)
Mobile: +32 476 562972
email: [EMAIL PROTECTED]
*********************************************
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>