Re: Built-in templates for maps and arrays

Yes, I've given this some thought and I'm not sure I know the right answer yet, but I recognise the problem.

The biggest problem with recursive descent processing of maps and arrays is that you don't have enough context for matching them. There's no equivalent of element names in JSON, but the proposed match="record(longiture, latitude)" tries to get around that by matching maps structurally; that's a step forward. The other problem is you can't access informtion higher up the tree, which means you need to make greater use of tunnel parameters, and one of the obstacles here is that you can't reference tunnel parameters in your match patterns; I've been thinking if we can find a way around that.

The default template rules are probably the easiest part of the overall problem.

A few use cases would be handy!

Michael Kay
Saxonica

> On 3 Dec 2020, at 12:16, Tom Hillman <tom@expertml.com> wrote:
> 
> Hi,
> 
> Now that we can match templates on maps, arrays, strings, and so on, is it time to consider adding built-in templates for some of the data structures?  I think these exist already for e.g. text-only copy, deep copy, deep skip, and the proposed fail mode types, but not for shallow skip and shallow copy.
> 
> Something like the following for arrays:
> 
> 
> 
> 	<xsl:template match=".[. instance of array(*)]" mode="shallow-skip">
> 		<xsl:for-each-member select="$array">
> 			<xsl:apply-templates select="." mode="#current"/>
> 		</xsl:for-each-member>
> 	</xsl:template>
> 	
> 	<xsl:template match=".[. instance of array(*)]" mode="shallow-copy" as="array(*)">
> 		<xsl:iterate select="1 to array:size($array)">
> 			<xsl:param name="result" as="array(*)" select="array{}"/>
> 			<xsl:on-completion>
> 				<xsl:sequence select="$result"/>
> 			</xsl:on-completion>
> 			<xsl:variable name="head">
> 				<xsl:apply-templates select="$array(.)" mode="#current"/>
> 			</xsl:variable>
> 			<xsl:next-iteration>
> 				<xsl:with-param name="result" select="array:append($result, $head)"/>
> 			</xsl:next-iteration>
> 		</xsl:iterate>
> 	</xsl:template>
> 
> 
> Maps might need a little thinking about in that I can't think of a way to write a match test for both the value and the key of a map member - any suggestions?
> 
> _________________
> Tomos Hillman
> eXpertML Ltd
> +44 7793 242058

Received on Thursday, 3 December 2020 12:47:37 UTC