Re: saxon:preview and SAXTransformerFactory

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: saxon:preview and SAXTransformerFactory

Mark R. Diggory-2
I wasn't subscribed to the list and missed your response.

I notice in Saxon 8 SA there is a "readonly" functionality, does this
provide an optimization similar to preview did?

-Mark

Michael Kay wrote:

> I'm sorry, but saxon:preview is becoming a rather distant memory and I can't
> answer this question without doing a lot of digging. I don't remember
> exactly what the problems with saxon:preview were when using a
> SAXTransformerHandler, or whether the problems would also apply when using
> an XMLFilter. It's probably reasonable to assume that the same restrictions
> apply, unless trial-and-error shows otherwise.
>
> saxon:preview eventually became unmaintainable for two reasons: firstly, it
> distorted the architecture of the product too much, and secondly, it limited
> the ability to do optimizations such as lazy evaluation. It's therefore not
> present in Saxon 8. There are cases where it comes in handy, but you need to
> be aware that it's a dead end.
>
> Michael Kay
> http://www.saxonica.com/ 
>
>
>>-----Original Message-----
>>From: [hidden email]
>>[mailto:[hidden email]] On Behalf Of
>>Mark R. Diggory
>>Sent: 16 March 2005 21:26
>>To: [hidden email]
>>Subject: [saxon] saxon:preview and SAXTransformerFactory
>>
>>I'm trying to use saxon:preview in a JAXP SAX Filter Chain. I notice
>>theres a reference that saxon:preview is not available in usage with
>>TransformerHandler. I'm assuming this means all of the
>>SAXTransformer API?
>>
>>http://saxon.sourceforge.net/saxon6.5.3/extensions.html#saxon:preview
>>
>>
>>><saxon:preview> is not supported when a transformation is run using
>>>the JAXP 1.1 TransformerHandler interface. It works when using the
>>>Saxon command line, or when invoking a transformation using the
>>>transform() method.
>>
>>The way I'm using it is analogous to the following (but with more
>>Filters in the chain:
>>
>>
>>>//         Set up to read the input file
>>>            SAXParserFactory spf = SAXParserFactory.newInstance();
>>>            SAXParser parser = spf.newSAXParser();
>>>            XMLReader reader = parser.getXMLReader();
>>>            
>>>            SAXTransformerFactory stf =
>>>                  (SAXTransformerFactory)
>>
>>TransformerFactory.newInstance();
>>
>>>                
>>>            Templates template = stf.newTemplates(new
>>
>>StreamSource(this.getClass().getResourceAsStream("pruneDataDsc
>>r.xsl")));
>>
>>>            XMLFilter filter1 = stf.newXMLFilter(template);
>>>            filter1.setParent(reader);
>>>              
>>>            // Set up the output stream
>>>            File file = File.createTempFile("study", "document");
>>>            log.debug(file.getAbsolutePath());
>>>            StreamResult result = new StreamResult(new
>>
>>FileWriter(file));
>>
>>>                  
>>>            // Set up the transformer to process the SAX
>>
>>events generated
>>
>>>            // by the last filter in the chain
>>>            Transformer transformer = stf.newTransformer();
>>>            SAXSource transformSource = new
>>
>>SAXSource(filter1, new InputSource(this.access()));
>>
>>>            transformer.transform(transformSource, result);
>>>            
>>
>>thanks,
>>Mark Diggory
>>
>>
>>
>>
>>-------------------------------------------------------
>>SF email is sponsored by - The IT Product Guide
>>Read honest & candid reviews on hundreds of IT Products from
>>real users.
>>Discover which products truly live up to the hype. Start reading now.
>>http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
>>_______________________________________________
>>saxon-help mailing list
>>[hidden email]
>>https://lists.sourceforge.net/lists/listinfo/saxon-help
>>
>
>
>
>
>
> -------------------------------------------------------
> SF email is sponsored by - The IT Product Guide
> Read honest & candid reviews on hundreds of IT Products from real users.
> Discover which products truly live up to the hype. Start reading now.
> http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click



-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

RE: Re: saxon:preview and SAXTransformerFactory

Michael Kay
The new "readonly" facility addresses the same objectives as the old
"preview" mode, but it works in a very different way internally. It's
basically an optimization of an expression such as

<xsl:copy-of select="doc('a.xml')//simple-path"/>

that evaluates this expression (returning a sequence of nodes) without ever
reading the whole of a.xml into memory. Because "copy-of" is part of the
expression, the nodes that are returned are parentless. This is much cleaner
than the preview mechanism, because the 1.0 model didn't allow parentless
nodes.

The only difference (apart from performance) from a standard evaluation of
the above expression is that doc('a.xml') is a snapshot: if you execute the
same expression twice, the contents of the document might have been modified
in between.

Typical usage is something like:

<xsl:function name="f:chapters">
  <xsl:param name="input"/>
  <xsl:copy-of select="doc($input)//chapter"/>
</xsl:function>

<xsl:for-each select="f:chapters('book.xml')">
  <xsl:result-document href="chap{position()}.xml">
    <xsl:sequence select="."/>
  </xsl-document>
</xsl:for-each>

Michael Kay
http://www.saxonica.com/

> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of
> Mark R. Diggory
> Sent: 25 September 2005 21:25
> To: [hidden email]
> Subject: [saxon] Re: saxon:preview and SAXTransformerFactory
>
> I wasn't subscribed to the list and missed your response.
>
> I notice in Saxon 8 SA there is a "readonly" functionality, does this
> provide an optimization similar to preview did?
>
> -Mark
>
> Michael Kay wrote:
> > I'm sorry, but saxon:preview is becoming a rather distant
> memory and I can't
> > answer this question without doing a lot of digging. I
> don't remember
> > exactly what the problems with saxon:preview were when using a
> > SAXTransformerHandler, or whether the problems would also
> apply when using
> > an XMLFilter. It's probably reasonable to assume that the
> same restrictions
> > apply, unless trial-and-error shows otherwise.
> >
> > saxon:preview eventually became unmaintainable for two
> reasons: firstly, it
> > distorted the architecture of the product too much, and
> secondly, it limited
> > the ability to do optimizations such as lazy evaluation.
> It's therefore not
> > present in Saxon 8. There are cases where it comes in
> handy, but you need to
> > be aware that it's a dead end.
> >
> > Michael Kay
> > http://www.saxonica.com/ 
> >
> >
> >>-----Original Message-----
> >>From: [hidden email]
> >>[mailto:[hidden email]] On Behalf Of
> >>Mark R. Diggory
> >>Sent: 16 March 2005 21:26
> >>To: [hidden email]
> >>Subject: [saxon] saxon:preview and SAXTransformerFactory
> >>
> >>I'm trying to use saxon:preview in a JAXP SAX Filter Chain. I notice
> >>theres a reference that saxon:preview is not available in usage with
> >>TransformerHandler. I'm assuming this means all of the
> >>SAXTransformer API?
> >>
> >>http://saxon.sourceforge.net/saxon6.5.3/extensions.html#saxo
> n:preview
> >>
> >>
> >>><saxon:preview> is not supported when a transformation is run using
> >>>the JAXP 1.1 TransformerHandler interface. It works when using the
> >>>Saxon command line, or when invoking a transformation using the
> >>>transform() method.
> >>
> >>The way I'm using it is analogous to the following (but with more
> >>Filters in the chain:
> >>
> >>
> >>>//         Set up to read the input file
> >>>            SAXParserFactory spf = SAXParserFactory.newInstance();
> >>>            SAXParser parser = spf.newSAXParser();
> >>>            XMLReader reader = parser.getXMLReader();
> >>>            
> >>>            SAXTransformerFactory stf =
> >>>                  (SAXTransformerFactory)
> >>
> >>TransformerFactory.newInstance();
> >>
> >>>                
> >>>            Templates template = stf.newTemplates(new
> >>
> >>StreamSource(this.getClass().getResourceAsStream("pruneDataDsc
> >>r.xsl")));
> >>
> >>>            XMLFilter filter1 = stf.newXMLFilter(template);
> >>>            filter1.setParent(reader);
> >>>              
> >>>            // Set up the output stream
> >>>            File file = File.createTempFile("study", "document");
> >>>            log.debug(file.getAbsolutePath());
> >>>            StreamResult result = new StreamResult(new
> >>
> >>FileWriter(file));
> >>
> >>>                  
> >>>            // Set up the transformer to process the SAX
> >>
> >>events generated
> >>
> >>>            // by the last filter in the chain
> >>>            Transformer transformer = stf.newTransformer();
> >>>            SAXSource transformSource = new
> >>
> >>SAXSource(filter1, new InputSource(this.access()));
> >>
> >>>            transformer.transform(transformSource, result);
> >>>            
> >>
> >>thanks,
> >>Mark Diggory
> >>
> >>
> >>
> >>
> >>-------------------------------------------------------
> >>SF email is sponsored by - The IT Product Guide
> >>Read honest & candid reviews on hundreds of IT Products from
> >>real users.
> >>Discover which products truly live up to the hype. Start
> reading now.
> >>http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
> >>_______________________________________________
> >>saxon-help mailing list
> >>[hidden email]
> >>https://lists.sourceforge.net/lists/listinfo/saxon-help
> >>
> >
> >
> >
> >
> >
> > -------------------------------------------------------
> > SF email is sponsored by - The IT Product Guide
> > Read honest & candid reviews on hundreds of IT Products
> from real users.
> > Discover which products truly live up to the hype. Start
> reading now.
> > http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
>
>
>
> -------------------------------------------------------
> SF.Net email is sponsored by:
> Tame your development challenges with Apache's Geronimo App
> Server. Download
> it for free - -and be entered to win a 42" plasma tv or your very own
> Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
> _______________________________________________
> saxon-help mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help
>




-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help