[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Need help with apply-templates to set variables

Subject: Re: Need help with apply-templates to set variables
From: Brad Cox <bcox@xxxxxxxxxxxxxxxxx>
Date: Sun, 3 Feb 2002 16:15:41 -0500
apply temp xml

On Sunday, February 3, 2002, at 03:13 PM, Trevor Nash wrote:
You probably need to change the signature (and internal logic) of
addPage to handle DOM nodes instead of strings - without knowing what
the structure of the overall application is, it is hard to give
detailed advice.

Thanks. Got that far based on advice from another list. See the enclosed file, which still isn't working right. The StringWriter variable winds up containing an empty string. Any advice would be MOST welcome.


The point is to parse a multi-page document into individual Velocity template pages and to hold these in a cache of velocity template pages.

I never imagined such a simple task would be such a hassle. Why it makes sense for string() to to discard part of its contents (trees or not) completely eludes me.

public Page getPage(IntegerField pageNumber) throws Fault
{
System.err.println("pages:"+pages);
System.err.println("lastModified"+
" xml:"+ (lastModified-xmlFile.lastModified())+
" xsl:"+ (lastModified-xslFile.lastModified())
);
if (pages == null ||
xmlFile.lastModified() > lastModified ||
xslFile.lastModified() > lastModified)
{
if (!xmlFile.exists()) throw new Fault(this + " can't find:"+xmlFile, null);
if (!xslFile.exists()) throw new Fault(this + " can't find:"+xslFile, null);
try
{
System.err.println("transforming:"+ xmlFile + " with " + xslFile);
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer(
new StreamSource(xslFile.toString())
);
transformer.setParameter("task", this);
StringWriter sw = new StringWriter();
transformer.transform(
new StreamSource(xmlFile.toString()),
new StreamResult(sw)
);
System.err.println("discarded text:"+sw);
this.lastModified = System.currentTimeMillis();
}
catch (Exception e)
{
throw new Fault("Exception transforming:"+xmlFile+ " with:"+xslFile, e);
}
}
else System.err.println("reusing cached page");
return (Page)pages.get(pageNumber.getInt());
}
public void addPage( String ident, org.w3c.dom.Node body)
{
try
{
StringWriter sw = new StringWriter();
Serializer serializer = SerializerFactory.getSerializer
(OutputProperties.getDefaultMethodProperties("html"));
serializer.setWriter(sw);
serializer.asDOMSerializer().serialize(body);
System.err.println("addPage:"+sw);
pages.add(new Page(this, ident, "<h2>sw</h2>"+sw, new IntegerField(pages.size())));
}
catch (IOException e)
{
System.err.println("IOException:" + ident);
e.printStackTrace();
}
}



XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.