[Home] [By Thread] [By Date] [Recent Entries]
On 30.08.2019 23:49, Martin Honnen martin.honnen@xxxxxx wrote:
On 30.08.2019 23:18, Martynas JuseviDius martynas@xxxxxxxxxxxxx wrote:
Some buffering will be needed, converting the whole XML map structure in an XPath 3.1 map stored in an accumulator might also work. While storing the XML "map" in an XPath 3.1 is possible such a map doesn't preserve the order of the "string" elements so perhaps using a sequence of maps (or, as Saxon 9.9 EE also supports a tuple type_) is better: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="3.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:map="http://www.w3.org/2005/xpath-functions/map"
exclude-result-prefixes="#all"
expand-text="yes"><xsl:output indent="yes"/> <xsl:mode streamable="yes" on-no-match="shallow-skip" use-accumulators="values map-id"/> <xsl:accumulator name="map-id" initial-value="()" streamable="yes"
as="xs:string?">
<xsl:accumulator-rule match="array/map" select="()"/>
<xsl:accumulator-rule match="/array/map/string[@key = 'id']/text()"
select="string()"/>
</xsl:accumulator> <xsl:accumulator name="values" as="tuple(key: xs:string, val:
xs:string)*" streamable="yes" initial-value="()">
<xsl:accumulator-rule match="array/map" select="()"/>
<xsl:accumulator-rule match="array/map/*[@key[not(. =
'id')]]/text()"
select="$value, map{ 'key' : string(../@key), 'val'
:string() }"/>
</xsl:accumulator> <xsl:template match="array/map">
<items>
<xsl:apply-templates/>
<xsl:apply-templates select="accumulator-after('values')"
mode="item">
<xsl:with-param name="map-id"
select="accumulator-after('map-id')"/>
</xsl:apply-templates>
</items>
</xsl:template> <xsl:template match=".[. instance of tuple(key: xs:string, val:
xs:string)]" mode="item">
<xsl:param name="map-id"/>
<item>
<id>{$map-id}</id>
<key>{?key}</key>
<val>{?val}</val>
</item>
</xsl:template></xsl:stylesheet> Needs to be run in Saxon EE with --allowSyntaxExtensions:on for the tuple type syntax extension to be recognized and supported.
|

Cart



