|
[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Order in an XML document
> My problem is simple: if I compare 2 elements A and B the
> results can be
>
> [1] A and B are not in the same document
> [2] A is before B
> [3] B is before A
> [4] A and B are equal
> [5] A is within B
> [6] B is within A
>
Relationships between nodes are determined using axes.
For clarity I'll use an is-subset() function that tests whether one nodeset
is a subset of
another. You can implement this test using count() and the union operator
but it gets difficult to read. Take "is-subset($X, $Y)" as a macro for
"count($X|$Y)=count($Y)".
<xsl:template name="compare">
<xsl:param name="A"/>
<xsl:param name="B"/>
<xsl:choose>
<xsl:when test="is-subset($A, $B) and is-subset($B,
$A)">4</xsl:when>
<xsl:when test="is-subset($A, $B/preceding::*)">2</xsl:when>
<xsl:when test="is-subset($A, $B/following::*)">3</xsl:when>
<xsl:when test="is-subset($A, $B/descendant::*)">5</xsl:when>
<xsl:when test="is-subset($A, $B/ancestor::*)">6</xsl:when>
<xsl:otherwise>1</xsl:otherwise>
</xsl:choose>
</xsl:template>
Mike K
***************************************************************************
This is xml-dev, the mailing list for XML developers.
To unsubscribe, mailto:majordomo@x...&BODY=unsubscribe%20xml-dev
List archives are available at http://xml.org/archives/xml-dev/
***************************************************************************
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|
|||||||||

Cart








