xsl-list
[Top] [All Lists]

Re: [xsl] Using sibling value in streaming mode

2019-08-30 16:49:30
On 30.08.2019 23:18, Martynas Jusevičius martynas(_at_)atomgraph(_dot_)com 
wrote:

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?


How large are the maps? Can't you afford to switch to "normal"
processing with e.g.

<xsl:template match="map">
  <xsl:apply-templates select="copy-of()" mode="non-streaming"/>
</xsl:template>

<xsl:template match="map" mode="non-streaming">
  <items>
    <xsl:apply-templates select="string[not(@key = 'id')]" mode="#current">
      <xsl:with-param name="id" select="string[@key = 'id']"/>
    </xsl:apply-templates>
  </items>
</xsl:template>

<xsl:template match="string" mode="non-streaming">
  <xsl:param name="id"/>
  <item xsl:expand-text="yes">
    <id>{$id}</id>
    <key>{@key}</key>
    <val>{.}</val>
  </item>
</xsl:template>


?

Some buffering will be needed, converting the whole XML map structure in
an XPath 3.1 map stored in an accumulator might also work.
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>