An interesting and well-asked question! In my opinion, using every and satisfies to overcome the existential properties of sequence comparison is a very efficient and fairly canonical method.
But since you are asking about another approach: how about sorting sequences before comparing them with deep-equal() ? Assume the two sequences in the following stylesheet:
<?xml version="1.0" encoding="UTF-8" ?> <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output method="text"/> <xsl:variable name="A" select="('a','b','c')"/> <xsl:variable name="B" select="('a','c','b')"/> <xsl:template match="/"> <xsl:choose> <xsl:when test="deep-equal($A,$B)"> <xsl:text>DEEP-EQUAL!</xsl:text> </xsl:when> <xsl:otherwise> <xsl:text>NOT DEEP-EQUAL</xsl:text> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:transform>
And of course, this conversion returns
NOT DEEP-EQUAL
But if you sort the sequences before comparing them, for example, with a custom function using xsl:perform-sort , see the corresponding part of the specification :
<?xml version="1.0" encoding="UTF-8" ?> <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" xmlns:local="www.local.com" extension-element-prefixes="local" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xsl:output method="text"/> <xsl:variable name="A" select="('a','b','c')"/> <xsl:variable name="B" select="('a','c','b')"/> <xsl:template match="/"> <xsl:choose> <xsl:when test="deep-equal(local:sort($A),local:sort($B))"> <xsl:text>DEEP-EQUAL!</xsl:text> </xsl:when> <xsl:otherwise> <xsl:text>NOT DEEP-EQUAL</xsl:text> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:function name="local:sort" as="xs:anyAtomicType*"> <xsl:param name="in" as="xs:anyAtomicType*"/> <xsl:perform-sort select="$in"> <xsl:sort select="."/> </xsl:perform-sort> </xsl:function> </xsl:transform>
then the result will be
DEEP-EQUAL!
EDIT : actually establishing equality will mean that not only the order doesn't matter, but the duplicates shouldn't matter either. Therefore, correct uniform equality will also mean applying distinct-values() to sequence variables:
<xsl:when test="deep-equal(local:sort(distinct-values($A)),local:sort(distinct-values($B)))">
Mathias müller
source share