On Fri, Jun 10, 2016 at 09:30:30AM -0000, Michael Kay mike@xxxxxxxxxxxx
scripsit:
> If you have the opportunity to use XSLT 3.0, this might be a good use
> for accumulators; these visit every node in the tree and compute a
> value based on the previous value and the content of the node: in your
> case the value of the accumulator could be the hash function. With 2.0
> you could achieve a similar effect using apply-templates with sibling
> recursion.
I might well be able to use XSLT 3.0; accumulators are unfamiliar but
this looks (from a quick read) like a simple case.
Just as soon as I get all the cyclic references out of the input,
anyway....
> Something like this:
>
> <xsl:template match="*" mode="hash" as="xs:integer">
> <xsl:param name="h" as="xs:integer"/>
> <xsl:apply-templates select="." mode="local-hash">
> <xsl:with-param name="h">
> <xsl:apply-templates select="following-sibling::*[1]">
> <xsl:with-param name="h">
> <xsl:apply-templates select="*[1]">
> <xsl:with-param name="h" select="$h"/>
> </
> </
> </
> </
> </
> and then in mode local-hash, you can define rules for individual
> elements that compute a hash for that particular element based on its
> attributes and text content; each template takes the old hash value
> and updates it as necessary. To combine two hash values you can use
> addition, or if you prefer an XOR function which you can get from the
> EXPath binary library.
Thank you!
That's pretty much precisely what's wanted.
-- Graydon
|