XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Jack TanSubject: Treatment of reserved characters in text
Author: Jack Tan
Date: 01 Sep 2005 04:24 AM
I am new to XQUERY and I am trying to process large XML file containing text. Part of the text contains reserved characters such as "&". I want to remove "&" from the text. For example xml fragment has:

<label>"[(n==32) &amp;&amp; (Pmax - Pmin)&lt;20]"</label>

How "&&" can be replaced by " " using XQUERY?
Along the same line, I tried to replace selected characters using

let $answer := fn:replace($string, "[-+ <>|*]", " "]

and it almost worked, with exception of "-". To complete this I have to aply in a separate line

let $answer1 := fn:replace($answer, "-", " "]

Why fn:replace did not worked the first time?

This is probably a trivial question, and the answer must be available somewhere in www.w3.org but I could not find it.

Thx for help.

Jack

Postnext
Alberto MassariSubject: Treatment of reserved characters in text
Author: Alberto Massari
Date: 01 Sep 2005 06:58 AM
Hi Jack,
what version of Stylus are you using? I tried on version 6 Release 3,
build 377m the following XQuery:

let $string:="-aaa-",
$answer := fn:replace($string, "[-+ <>|*]", " ")
return $answer

and I got the expected " aaa " answer.

Alberto

Postnext
Jack TanSubject: Treatment of reserved characters in text
Author: Jack Tan
Date: 01 Sep 2005 12:25 PM
Alberto,

You are right, it indeed works with "-" (it must be a late night candle that blured my vision). Thanks.

Any suggestions about removal of "&" from the text?

Best regards,

Jack

Postnext
Alberto MassariSubject: Treatment of reserved characters in text
Author: Alberto Massari
Date: 01 Sep 2005 12:59 PM
Hi Jack,
you can use the fn:replace as in the previous example; you just need to keep in mind that "&" must be always represented as "&amp;", and write

$result:=fn:replace($string,"-+<> []&amp;"," ")

Hope this helps,
Alberto

Postnext
Jack TanSubject: Treatment of reserved characters in text
Author: Jack Tan
Date: 01 Sep 2005 01:48 PM
I tried this

let $rslt := fn:replace($txt, "[+()=<>|&amp*:-]"," ")

but, it comes back with an error: "Unrecognized character '"' (0x22)". Part of the expression is also highlighted red (Studio 6, rel. 3, build 377m).

So perhaps the question is: how can I enter the query so the evaluator will accept "&" as a part of string between "" rather than reserved character? Any control flags to properly configure the environment/engine?

Jack

Posttop
Tony LavinioSubject: Treatment of reserved characters in text
Author: Tony Lavinio
Date: 01 Sep 2005 05:55 PM
You used &amp but forgot the ; at the end.

 
Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

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