xsl-list
[Top] [All Lists]

Re: [xsl] filtering maps by key characteristics?

2020-08-24 11:48:54
Perhaps something like 

map:remove($map, map:keys($map)[starts-with(map:keys(.), 'GUID-')])

Michael Kay
Saxonica

On 24 Aug 2020, at 17:41, Graydon graydon(_at_)marost(_dot_)ca 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

Hello --

I have a content set traversal that creates map entries when it finds id
attributes in the source tree; one map entry maps a generated GUID to
the node with the id attribute, and another map entry maps the value of
the id attribute to the same GUID.

The result is stored as a sequence of singleton maps:

<xsl:variable as="map(*)+" name="traversalMap">
 <xsl:apply-templates mode="traverse" select="$contentSet" />
</xsl:variable>

This sequence of ~map entries then get filtered into two merged maps, one 
with the GUID-to-element mapping, and one with the id-value-to-GUID mapping:

<xsl:variable as="map(xs:string,element())" name="GUID2nodeMap">
 <xsl:map>
   <xsl:sequence select="$traversalMap ! .[starts-with(map:keys(.), 
'GUID-')]" />
 </xsl:map>
</xsl:variable>
<xsl:variable as="map(xs:string,xs:string)" name="DITA2GUIDmap">
 <xsl:map>
   <xsl:sequence select="$traversalMap ! .[not(starts-with(map:keys(.), 
'GUID-'))]" />
 </xsl:map>
</xsl:variable>

(I thought it would be easier to split a sequence of ~map entries into
two maps than it would be to traverse the tree twice.)

And it works, but it wouldn't work if I was starting with a merged map,
rather than a sequence of ~map entries/singleton maps.

Is there a way to do this with a merged map, that is, filter a map with
multiple entries by testing characteristics of the keys without having
to reconsitute each entry?

$traverseMap[starts-with(map:key(.),'GUID-')]

doesn't work; the context is the WHOLE map, not a map entry.  And there
doesn't seem to be a way to treat a map as a sequence of map entries.

Is there one?  Am I missing something?

Thanks!

-- 
Graydon Saunders  | graydonish(_at_)gmail(_dot_)com
Þæs oferéode, ðisses swá mæg.
-- Deor  ("That passed, so may this.")

--~----------------------------------------------------------------
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>