Subject: Re: [xsl] filtering maps by key characteristics? From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Mon, 24 Aug 2020 16:48:50 -0000 |
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@xxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> 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@xxxxxxxxx > CC&s oferC)ode, C0isses swC! mC&g. > -- Deor ("That passed, so may this.")
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] filtering maps by key charact, Graydon graydon@xxxx | Thread | Re: [xsl] filtering maps by key cha, Graydon graydon@xxxx |
[xsl] filtering maps by key charact, Graydon graydon@xxxx | Date | Re: [xsl] filtering maps by key cha, Graydon graydon@xxxx |
Month |