You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Nicholas Sushkin <ni...@scientist.com> on 2001/02/12 23:34:39 UTC
do-nothing-special extension?
Hi,
How do you implement an extension element function that does what the
default XSLT processor does, that is copies the transformed xml to the
output tree? Do you do something like
context.processor.writeChildren( context.processor.getDocumentHandler(),
context.stylesheetTree,
(ElemTemplateElement)elem,
context.sourceTree, context.sourceNode,
context.mode);
Thanks a lot,
Nick.
optimizing stylesheets for dynamic output
Posted by August Gresens <au...@blackhammer.com>.
Hi
We are creating a servlet based application that is using Xalan2 to
format output from a DOM. I'm wondering if anyone with experience
doing this has any performance tips. In particular, what types of
functions or ways of structuring the templates are more memory or
processor intensive than others.
Thanks
August
--
/////////////////////////
August Gresens
Black Hammer Productions
august@blackhammer.com
212 625-8980 ext 21
/////////////////////////
Re: do-nothing-special extension?
Posted by Gary L Peskin <ga...@firstech.com>.
Nicholas Sushkin wrote:
>
> Gary,
>
> Thanks a lot for remembering to get back to me. :)
>
> I think I solved my problem using the following code:
>
> public Element myextensionelement(XSLProcessorContext context, Element elem)
> throws ...
> {
> ...
> if (debug)
> {
> DocumentHandler defaultFormatter =
> context.processor.getFormatterListener();
>
> defaultFormatter.startElement("DebugMode",
> ((ElemExtensionCall)elem).getAttributeList());
>
> context.processor.writeChildren( defaultFormatter,
> context.stylesheetTree,
> (ElemTemplateElement)elem,
> context.sourceTree, context.sourceNode,
> context.mode);
>
> defaultFormatter.endElement("DebugMode");
> return null;
> }
> else
> {
> // do some real work
> }
> }
>
> Let me know if you see some some obvious problems with it.
Nicholas --
This looks fine for XalanJ1. For XalanJ2, you'd probably want something
like:
public Element myextensionelement(XSLProcessorContext context, Element
elem)
throws ...
{
...
if (debug)
{
ContentHandler defaultFormatter =
context.getTransformer().getContentHandler();
// Build Attributes
Attributes myAttrib = new AttributesImpl();
Enumeration allAttrib = ((ElemExtensionCall)
elem).enumerateLiteralResultAttributes();
while (allAttrib.hasMoreElements())
{
AVT myAVT = (AVT) allAttrib.nextElement();
myAttrib.addAttribute(myAVT.getURI(),
myAVT.getName(),
myAVT.getRawName(),
"CDATA",
((ElemExtensionCall) elem).getAttribute(myAVT.getRawName(),
context.getContextNode(),
context.getTransformer()));
}
defaultFormatter.startElement("", "DebugMode", "DebugMode",
myAttrib);
context.getTransformer().executeChildTemplates(elem,
context.getContextNode(),
context.getMode(),
true);
defaultFormatter.endElement("", "DebugMode", "DebugMode");
return null;
}
else
{
// do some real work
}
}
Gary
RE: do-nothing-special extension?
Posted by Nicholas Sushkin <ns...@openfinance.net>.
Gary,
Thanks a lot for remembering to get back to me. :)
I think I solved my problem using the following code:
public Element myextensionelement(XSLProcessorContext context, Element elem)
throws ...
{
...
if (debug)
{
DocumentHandler defaultFormatter =
context.processor.getFormatterListener();
defaultFormatter.startElement("DebugMode",
((ElemExtensionCall)elem).getAttributeList());
context.processor.writeChildren( defaultFormatter,
context.stylesheetTree,
(ElemTemplateElement)elem,
context.sourceTree, context.sourceNode,
context.mode);
defaultFormatter.endElement("DebugMode");
return null;
}
else
{
// do some real work
}
}
Let me know if you see some some obvious problems with it.
Thanks,
Nick.
> -----Original Message-----
> From: Gary L Peskin [mailto:garyp@firstech.com]
> Sent: Wednesday, February 28, 2001 12:47 AM
> To: xalan-dev@xml.apache.org
> Subject: Re: do-nothing-special extension?
>
>
> Nicholas Sushkin wrote:
> >
> > Gary,
> >
> > I am trying to write an extension element that will, depending
> on the value
> > of debug attribute, redirect the extension element's contents
> to a file or
> > act as if the element was not there (be transparent). For example:
>
> Nick --
>
> Did you ever get an answer for this. I have some time now and can look
> into this if you're still interested.
>
> Gary
>
Re: do-nothing-special extension?
Posted by Gary L Peskin <ga...@firstech.com>.
Nicholas Sushkin wrote:
>
> Gary,
>
> I am trying to write an extension element that will, depending on the value
> of debug attribute, redirect the extension element's contents to a file or
> act as if the element was not there (be transparent). For example:
Nick --
Did you ever get an answer for this. I have some time now and can look
into this if you're still interested.
Gary
RE: do-nothing-special extension?
Posted by Nicholas Sushkin <ns...@openfinance.net>.
Gary,
I am trying to write an extension element that will, depending on the value
of debug attribute, redirect the extension element's contents to a file or
act as if the element was not there (be transparent). For example:
Source.xml:
<a><b/></a>
Transform.xsl:
<template match="/">
<xsl:apply-templates select="b" mode="release"/>
<xsl:apply-templates select="b" mode="debug"/>
</template>
<template match="b" mode="release">
<ext:write file="output.xml" debug="no">
<release/>
</ext:write>
</template>
<template match="b" mode="debug">
<ext:write file="output.xml" debug="yes">
<debug/>
</ext:write>
</template>
Output:
a file output.xml with
<release/>
and the following XML in the standard output:
<debug/>
So, in my Java function that correspond to the ext:write element, I plan to
reuse the Redirect extension approach for the case when debug="no". However,
I am not sure how to replicate the default XSLT processor behavior when
debug="yes".
Thanks a lot for your help,
Nick.
> -----Original Message-----
> From: Gary L Peskin [mailto:garyp@firstech.com]
> Sent: Monday, February 12, 2001 6:06 PM
> To: xalan-dev@xml.apache.org
> Subject: Re: do-nothing-special extension?
>
>
> Nicholas Sushkin wrote:
> >
> > Hi,
> >
> > How do you implement an extension element function that does what the
> > default XSLT processor does, that is copies the transformed xml to the
> > output tree? Do you do something like
> >
> > context.processor.writeChildren(
> context.processor.getDocumentHandler(),
> > context.stylesheetTree,
> > (ElemTemplateElement)elem,
> > context.sourceTree,
> context.sourceNode,
> > context.mode);
>
> Nick --
>
> I'm not sure what you're asking here. Can you send along a small sample
> of the XML and XSLT that shows what you're trying to do?
>
> Gary
>
Re: do-nothing-special extension?
Posted by Gary L Peskin <ga...@firstech.com>.
Nicholas Sushkin wrote:
>
> Hi,
>
> How do you implement an extension element function that does what the
> default XSLT processor does, that is copies the transformed xml to the
> output tree? Do you do something like
>
> context.processor.writeChildren( context.processor.getDocumentHandler(),
> context.stylesheetTree,
> (ElemTemplateElement)elem,
> context.sourceTree, context.sourceNode,
> context.mode);
Nick --
I'm not sure what you're asking here. Can you send along a small sample
of the XML and XSLT that shows what you're trying to do?
Gary