Re: About node references
"Michael Kay" <[email protected]> Mon, 15 Dec 2008 16:39:34 -0000
| Newsgroups | gmane.text.xml.xslt.extensions |
|---|---|
| Message-ID | <DB56D4CEA997450EB4AF53337AF61F61@Sealion> |
>
> Probably I'm missing the nature of $function.
> Can you please describe what is it?
It's a function which given a key returns the corresponding value.
So one could envisage defining keys something like this:
<xsl:variable name="productKey" select="map(//product/@id,
xx:function('f:id-to-product'))"/>
<xsl:function name="f:id-to-product" as="element(product)">
<xsl:param name="id" select="xs:string"/>
<xsl:sequence select="//product[@id = $id]"/>
</xsl:function>
Which reveals the weakness in the approach - it would be hopelessly
inefficient.
Perhaps we need to say that a map is constructed from a sequence of mapEntry
objects, which can be constructed by a call on a mapEntry function like
this:
<xsl:variable name="product-id-map" as="x:map"
select="x:map(for $p in //product return x:mapEntry($p/@id, $p))"/>
<xsl:value-of select="get-from-map($product-id-map, 'id214')"/>
Now there's no explicit reference object visible to the user here. It's
merely something that the implementation might use internally, for example
if the above functions were to be implemented in XSLT itself.
Michael Kay
http://www.saxonica.com/