Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


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

From: "Michael Kay" <mike@------------>
To:
Date: 12/2/2005 3:40:00 PM
> 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/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent