[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

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


xsl normalize space
> 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/



PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.