[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Using sibling value in streaming mode

Subject: Using sibling value in streaming mode
From: "Martynas Jusevičius martynas@xxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 30 Aug 2019 21:18:32 -0000
 Using sibling value in streaming mode
Hi,

I've started looking into streaming recently (using Saxon 9.9). I have
a use case like this:

Input:

<array>
    <map>
       <string key="key1">value1</string>
       ...
       <string key="id">123456789</string>
       ...
       <string key="keyN">valueN</string>
    </map>
    ...
</array>

Required output:

<items>
    <item>
       <id>123456789</id>
       <key>key1<key>
       <val>value1</val>
    </item>
    ...
    <item>
       <id>123456789</id>
       <key>id<key>
       <val>123456789</val>
    </item>
    ...
    <item>
       <id>123456789</id>
       <key>keyN<key>
       <val>valueN</val>
    </item>
    ...
</items>

The value of <string key="id"> is used as <id> in <item> elements. The
problem is that <string key="id"> can occur in any position in the
<map>.

I've tried using an accumulator such as

<xsl:accumulator name="map-id" initial-value="()" streamable="yes"
as="xs:string?">
   <xsl:accumulator-rule match="/array/map/string[@key = 'id']/text()"
select="string(.)"/>
</xsl:accumulator>

and then

<item>
    <id><xsl:value-of select="accumulator-before('map-id')"/></id>
    ...
</item>

That worked partially -- only for sibling <string> elements that
followed the <string key="id">. Which is not surprising.

I've also tried accumulator-after('map-id') but got:

  XTSE3430: Template rule is not streamable
  * A call to accumulator-after() is consuming when there are no
preceding consuming instructions

Is it possible to have a streaming solution in this case?

Martynas

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.