Project

Profile

Help

Trouble with XSLT 3.0 streaming and accumulators

Added by Louis Thomas over 10 years ago

I'm trying to do a streaming transform, but accumulators don't seem to be working. I'm trying to convert some XML to tabular format (like CSV). I'm trying to pull out the child text content of a bunch of sibling elements and emit them in an order different from the source XML. It seems like accumulators are the simplest approach for this, but it's not working for me.

I'm using this sample XML:




   
      Gambardella, Matthew
      <title>XML Developer's Guide</title>
      Computer
      44.95
      2000-10-01
      An in-depth look at creating applications 
      with XML.
   
   
      Ralls, Kim
      <title>Midnight Rain</title>
      Fantasy
      5.95
      2000-12-16
      A former architect battles corporate zombies, 
      an evil sorceress, and her own childhood to become queen 
      of the world.
   

I'm using this sample XSLT:




   

   

   
      
   

   
   
      
      dummy
      ,
      ,

   

   
   id,title,author,price,publish_date



If I run it with the streamable="yes" commented out, then I get what I'd expect:

id,title,author,price,publish_date
bk101,
      XML Developer's Guide,

   bk102,
      Midnight Rain,

(Yes the formatting is wonky and I'm only pulling one field, but this is proof-of-concept and demonstates the problem.)

If I run it with the streamable="yes" commented in, I get nothing in the accumulator:

id,title,author,price,publish_date
bk101,
      ,

   bk102,
      ,

So it seems like my approach is valid but Saxon is not doing the right thing in steam mode. (I'm using SaxonEE9-5-1-2J.) The only thing I've been able to get to stick in the accumulator is the element name ("title").

What am I doing wrong? Is this the approach you would recommend for this task?


Replies (2)

RE: Trouble with XSLT 3.0 streaming and accumulators - Added by Michael Kay over 10 years ago

Sorry for the delay in responding to this: a cursory investigation led me into some dark corners of both the spec and the Saxon implementation, from which I have not yet fully emerged...

The basic problem is that (a) your code breaks a rule in the spec, namely that the new-value expression must be motionless, and (b) Saxon fails to detect this and report it as an error.

This is a pretty serious restriction and there's some debate about it in the WG. I need to think about it more deeply. There's an example in the current (internal) version of the spec that does pretty well exactly what you are trying to do, and a note against the example that says the example doesn't work! Sorry - you're at the bleeding edge here, but thanks for the input.

RE: Trouble with XSLT 3.0 streaming and accumulators - Added by Michael Kay over 10 years ago

I've done some work on this reported here:

https://saxonica.plan.io/issues/1890

As you see, there were a number of problems. With these bugs fixed, the accumulator can be defined as

   
      
   

Some issues remain, for example the interaction between a streamable mode and a non-streamable accumulator, which I have raised as spec issues.

    (1-2/2)

    Please register to reply