Subject: [xsl] Re: set:intersection oddity From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx> Date: Sat, 28 Jun 2003 22:55:36 +0200 |
"John Sharp" <jsharp@xxxxxx> wrote in message news:3EFDED78.290F7F48@xxxxxxxxx > Hello, I was attempting to use the set:intersection function > from http://exslt.org/sets. The examples showing the intersection > of cities with letters 'i' and 'e' work as given. However the > following does not work - INTERSECT1 is always empty. As it should be. You do not understand the definition of set:intersection(). The specification of this function says: "The set:intersection function returns a node set comprising the nodes that are within both the node sets passed as arguments to it. " http://www.exslt.org/set/functions/intersection/index.html That is, the equality-operation used in defining set:intersection() has node-identity semantics and not node-value semantics. > <INTERSECT1> > <xsl:copy-of select="set:intersection($data,$rules)"/> > </INTERSECT1> In your example below, the nodes in the $data and $rules are two distinct root nodes, they are not the same node, therefore set:intersection($data, $rules) must return the empty node-set. > <INTERSECT2> > <xsl:copy-of select="set:intersection($data,$data)"/> > </INTERSECT2> This intersects the root node contained in $data with itself -- therefore this is equivalent to: <xsl:copy-of select="$data"/> and must output the whole tree contained in $data, which is exactly what you got. > <INTERSECT3> > <xsl:copy-of select="$data[count(. | $rules) != count( $rules)]"/> > </INTERSECT3> > Here you want to xsl-copy all the nodes of $data (and this is just its root node) that are not identical to some of the nodes (just the root node) of $rules. As these are two distinct root nodes, the above is again equivalent to: <xsl:copy-of select="$data"/> An example, which will "work" is the following: <xsl:copy-of select="set:intersection($rules/*, $rules/*[position() mod 2 = 0])"/> This will intersect all the children of the root node with the ones that have an even position() and will xsl:copy-of the element $rules/*[2] Note to confused readers -- the OP has specified version="1.1" on the xsl:stylesheet instruction, this is why we do not need to convert RTFs to regular trees. ===== Cheers, Dimitre Novatchev. http://fxsl.sourceforge.net/ -- the home of FXSL > > <xsl:stylesheet > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > xmlns:saxon="http://saxon.sf.net/" > xmlns:set="http://exslt.org/sets" > extension-element-prefixes="set saxon" > version="1.1"> > > <xsl:template match="/"> > > <xsl:variable name="data"> > <Type>PMT</Type> > <Type>FUNC</Type> > </xsl:variable> > > <xsl:variable name="rules"> > <Type>PMT</Type> > <Type>DC_PARA</Type> > <Type>FUNC</Type> > </xsl:variable> > > > <INTERSECT1> > <xsl:copy-of select="set:intersection($data,$rules)"/> > </INTERSECT1> > > <INTERSECT2> > <xsl:copy-of select="set:intersection($data,$data)"/> > </INTERSECT2> > > <INTERSECT3> > <xsl:copy-of select="$data[count(. | $rules) != count( $rules)]"/> > </INTERSECT3> > > </xsl:template> > > > Here's the output:- > > <?xml version="1.0" encoding="UTF-8"?> > <INTERSECT1/> > <INTERSECT2> > <Type>PMT</Type> > <Type>FUNC</Type> > </INTERSECT2> > <INTERSECT3> > <Type>PMT</Type> > <Type>FUNC</Type> > </INTERSECT3>Execution time: 336 milliseconds > > > If I run the exslt web page example, it runs fine. > > Kind regards,John. > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] from a to b example - passing, dsk | Thread | RE: [xsl] set:intersection oddity, Michael Kay |
[xsl] from a to b example - passing, dsk | Date | [xsl] Binary characters in XML, Michael Leung |
Month |