Built-in templates for maps and arrays

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:16:33 UTC