Re: [xsl] [XSLT Streaming] I xsl:iterate over airport primary records; how do I get the following sibling airport continuation record?

Subject: Re: [xsl] [XSLT Streaming] I xsl:iterate over airport primary records; how do I get the following sibling airport continuation record?
From: "Michael Kay michaelkay90@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 31 Jan 2025 20:04:14 -0000
I think the best approach is probably to make a copy-of() the current record
within the xsl:iterate and pass it as a parameter to the next iteration. That
basically gives you a one-record lookbehind window, so in the body of
xsl:iterate you have access to both the current record and the previous one.

You could also group the record with its continuation using xsl:for-each-group
group-ending-with="...".

Or you could capture a copy of the most recent record in an accumulator.

It's true for XSLT generally, but for streaming in particular, that it's often
useful to break the processing up into multiple phases each of which does a
fairly simple job, and one approach here might be to have an initial phase of
processing that does nothing else other than creating a wrapper around a
record and its continuation record if present.

The diagnostics for code that isn't streamable are challenging. The
streamability rules are pretty complex and use some difficult concepts like
posture and sweep. I tried to find a compromise between a highly technical
explanation of what rules the code doesn't satisfy, and something more
informal that users are more likely to understand. But really it depends on
grasping the mental model: a template fires when the streaming parser
encounters a matching start tag, it gets one chance to read the content below
that start tag, and it can't read anything outside that start tag and its
matching end with a few exceptions: like, it can read the names and attributes
of ancestors, and it can read anything that was explicitly saved earlier in an
accumulator. There's no way you can ever look ahead of the current position in
the streamed input, so following-siblling is out of the question.

(Glad to see you got over your licensing problems, by the way.)

Michael Kay
Saxonica



> On 31 Jan 2025, at 19:25, Roger L Costello costello@xxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> Hi Folks,
>
> I am stream-processing a huge air navigation file that contains, among other
things, airport primary records:
>
> <ARINC>
>        ...
>        <record>
>                <ARINC_424-18_4_1_7_1_Airport_Primary_Records>
>                    data about an airport
>               </ARINC_424-18_4_1_7_1_Airport_Primary_Records>
>        </record>
>        ...
> </ARINC>
>
> In my program, I iterate over the airport primary records:
>
> <xsl:iterate
select="ARINC/record/ARINC_424-18_4_1_7_1_Airport_Primary_Records">
>    process an airport
> </xsl:iterate>
>
> Some--not all--airport primary records have a continuation record, which
immediately follows--is the first following sibling--the airport primary
record:
>
> <ARINC>
>        ...
>        <record>
>                <ARINC_424-18_4_1_7_1_Airport_Primary_Records>
>                    data about an airport
>               </ARINC_424-18_4_1_7_1_Airport_Primary_Records>
>        </record>
>        <record>
>
<ARINC_424-18_4_1_7_3_Airport_Flight_Planning_Continuation_Records>
>                    additional data about the airport
>
</ARINC_424-18_4_1_7_3_Airport_Flight_Planning_Continuation_Records>
>        </record>
>        ...
> </ARINC>
>
> Within the xsl:iterate loop, I tried to obtain the following continuation
record and store it into a variable:
>
> <xsl:iterate
select="ARINC/record/ARINC_424-18_4_1_7_1_Airport_Primary_Records">
>    <xsl:variable name="flt-pln-cont"
select="copy-of(../following-sibling::record[1]/ARINC_424-18_4_1_7_3_Airport_
Flight_Planning_Continuation_Records)"/>
>    process the airport and its continuation data
> </xsl:iterate>
>
> When I run my program, I get this error message:
>
> Static error at xsl:source-document on line 10 column 47 of
create-airports.xsl:
>  XTSE3430  The body of the xsl:source-document instruction is not
streamable
>  *  Cannot use the following-sibling axis when context posture is CLIMBING
(line 16)
>  *  Expression
parent::(element()|document-node())/following-sibling::record[1] requires
>  sorting nodes into document order
>
> What is the correct way to do this?
>
> /Roger

Current Thread