[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message]

[Newbie] Output contains space around each value -- how do I delete the space?

G. Ken Holman gkholman at CraneSoftwrights.com
Sat Apr 3 10:18:57 PST 2010


  [Newbie] Output contains space around each
	value -- how do I delete the space?
At 2010-04-03 10:05 -0400, Costello, Roger L. wrote:
>I have an XQuery that extracts all the data in a bookstore XML 
>document and formats the output as slash-delimited values. Here's my XQuery:
>
>-------------------------------------------------------
>declare namespace saxon = "http://saxon.sf.net/";
>declare option saxon:output "indent=no";
>declare option saxon:output "method=text";
>
>let $source := doc("bookstore.xml")
>
>return
>    (
>       string($source/bookstore/@storename),
>       "
>",
>       for $i in $source//book return
>          (
>              string($i/title),
>              "/",
>              string($i/author[1]),
>              "/",
>              string($i/date),
>              "/",
>              string($i/ISBN),
>              "/",
>              string($i/publisher),
>              "/",
>              string($i/cost[@currency='USD']),
>       "
>"
>          )
>    )
>-------------------------------------------------------
>
>The XQuery does almost exactly what I desire. However, there is a 
>space around each value. Here's the output:
>
>The ABC Book Store
>  The Origin of Wealth / Eric D. Beinhocker / 2006 / 1-57851-777-X / 
> Harvard Business School Press / 29.95
>...
>Why am I getting spaces around each value?

Because when two strings are added to the result, they are separted by spaces.

>How do I delete those spaces?

Typically you would use concat(), but in your case of having a slash 
delimiter, you need only use string-join():

       for $i in $source//book return
         string-join( (
              string($i/title),
              string($i/author[1]),
              string($i/date),
              string($i/ISBN),
              string($i/publisher),
              string($i/cost[@currency='USD'])
              ),
              "/" )

I hope this helps.

. . . . . . . . Ken

--
XSLT/XQuery training:         San Carlos, California 2010-04-26/30
Principles of XSLT for XQuery Writers: San Francisco,CA 2010-05-03
XSLT/XQuery training:                 Ottawa, Canada 2010-05-10/14
XSLT/XQuery/UBL/Code List training: Trondheim,Norway 2010-06-02/11
Vote for your XML training:   http://www.CraneSoftwrights.com/q/i/
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/q/
G. Ken Holman                 mailto:http://x-query.com/mailman/listinfo/talk
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/q/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal



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
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-2011 All Rights Reserved.