can I put a map inside an element? - Cannot add a map as a child of a constructed element

23 views Asked by At

and can I match on it?

I'm creating an intermediary document, and whilst I'd usually do that in terms of elements/attributes, its quite convenient for me to do it as a map, but saxon complains

Cannot add a map as a child of a constructed element

(I thought it would simply 'serialise' as some sort of xml structure)

<xsl:variable name="foo">
    <foo>
        <xsl:map>
            <xsl:map-entry key="'bar'" select="'wibble'"/>
        </xsl:map>
    </foo>
</xsl:variable>

maybe its not that surprising, (though you can put an element in a map).

So if I flip the whole intermediary structure into a map, then how do I apply-templates/match on a map?

1

There are 1 answers

6
Martin Honnen On BEST ANSWER

You can use e.g. <xsl:variable name="map1" select="map { 'bar' : 'wibble' }"/> and if you need it use e.g. <xsl:apply-templates select="$map1"/> and e.g. <xsl:template match=".[. instance of map(xs:string, xs:string)]">..</xsl:template>.

In terms of navigating/matching maps there is a lack of ancestor navigation, you might (if you use Saxon PE/EE) want to look into the various extensions Saxon offers for processing maps https://www.saxonica.com/html/documentation12/functions/saxon/with-pedigree.html, https://www.saxonica.com/html/documentation12/functions/saxon/pedigree.html. There are also some papers and/or blogs entries by Michael Kay/Saxonica on that, I think.