[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Need help with apply-templates to set variables


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


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