Project

Profile

Help

Usage of except operator

Added by Anonymous almost 18 years ago

Legacy ID: #3867297 Legacy Poster: Marco Baumgartl (killernase)

Hi, I have the following content in this two variables: <xsl:variable name="foo"> <xsl:copy-of select="$valid_values/value" /> </xsl:variable> <xsl:variable name="bar"> <xsl:copy-of select="$x-axis-data/item/value[position() &gt; 1]" /> </xsl:variable> The content of these variables look like this: <foo> <value>73,5</value> <value>86,0</value> <value>98,5</value> <value>73,5</value> <value>86,0</value> <value>98,5</value> </foo> <bar> <value>73,5</value> <value>86,0</value> <value>98,5</value> <value>61,0</value> <value>76,0</value> <value>88,5</value> <value>101,0</value> </bar> I want only these value-elements that are in $bar but not in $foo: <result> <xsl:copy-of select="$bar except $foo" /> </result> and get so following result: <result> <value>73,5</value> <value>86,0</value> <value>98,5</value> <value>61,0</value> <value>76,0</value> <value>88,5</value> <value>101,0</value> </result> which seem to contain all value of $bar :-( Where is my mistake? regards Marco


Replies (1)

RE: Usage of except operator - Added by Anonymous almost 18 years ago

Legacy ID: #3867341 Legacy Poster: Michael Kay (mhkay)

"except" works on node identity, not node value. Because you copied the original source nodes, the nodes in foo all have distinct identity from the nodes in bar. Assuming that the source nodes are the same in both cases, you could do: <xsl:variable name="foo" select="$valid_values/value" /> <xsl:variable name="bar" select="$x-axis-data/item/value[position() &gt; 1]" /> and "except" would then work: this would also save the considerable cost of making the copies. But if you really need to make copies, change "$bar except $foo" to "$bar[not(.=$foo)]". Incidentally, there's nothing specific to Saxon in this question. General XSLT/XPath coding questions are best asked on the xsl-list at www.mulberrytech.com

    (1-1/1)

    Please register to reply