xsl-list
[Top] [All Lists]

RE: Comparing XML, xsl:normalize-space and schemaTron

2005-12-02 08:39:08
If I have the following XML instance document (notice the spaces) :-

<compare>
      <compareWith>   A</compareWith>
      <comparisonValues>
              <value>B</value>
              <value>   A   </value>
              <value>A </value>
      </comparisonValues>
</compare>

and I use this expression :-

normalize-space(/compare/comparisonValues/value[3]) = 
normalize-space(/compare/compareWith)

the result is true.

If I remove [3] it is an error ('too many items')

So presumably you are using XPath 2.0. In 1.0, it would simply take the
first node in the node-set.

This seems OK (although it would be nice if I *could* use 
normalize-space on 
all of the nodes returned)

In 2.0, use /compare/compareWith/normalize-space(.) or

for $c in /compare/compareWith return normalize-space($c)

I have also tried (successfully) using xsl:key + the key() 
function to 
create a set of the values in 1 document and then, using key(), check 
whether the value of a node in the other document exists in 
that set. This 
worked and I was able to do the compare using 
normalized-space values, but I 
am a bit wary of whether this approach is costly in terms of 
performance - 
can anyone comment ??

Measure it and see. Keys usually improve performance provided you use them
more than once (well, say more than 5 times).

Michael Kay
http://www.saxonica.com/



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>