[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?

Costello, Roger L. costello at mitre.org
Sat Apr 3 10:05:47 PST 2010


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

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 
 DOM Scripting / Jeremy Keith / 2005 / 1-59059-533-5 / friends of ed / 34.99 
 Guns, Germs, and Steel / Jared Diamond / 2005 / 0-393-06131-0 / W. W. Norton & Company, Ltd. / 24.99 
 Economics in One Lesson / Henry Hazlitt / 1946 / 0-517-54823-2 / Three Rivers Press / 11.00 
 How to Read a Book / Mortimer J. Adler / 1940 / 0-671-21280-x / Simon & Schuster, Inc. / 15.00 
 Don't Make Me Think / Steve Krug / 2006 / 0-321-34475-8 / New Riders / 40.00 
 Bulletproof Ajax / Jeremy Keith / 2007 / 0-321-47266-7 / New Riders / 34.99


Why am I getting spaces around each value?

How do I delete those spaces?

Here's the input XML document:

<?xml version="1.0"?>
<bookstore storename="The ABC Book Store">
    <book>
        <title>The Origin of Wealth</title>
        <author>Eric D. Beinhocker</author>
        <date>2006</date>
        <ISBN>1-57851-777-X</ISBN>
        <publisher>Harvard Business School Press</publisher>
        <cost currency="USD">29.95</cost>
    </book>
    <book>
        <title>DOM Scripting</title>
        <author>Jeremy Keith</author>
        <date>2005</date>
        <ISBN>1-59059-533-5</ISBN>
        <publisher>friends of ed</publisher>
        <cost currency="USD">34.99</cost>
    </book>
    <book>
        <title>Guns, Germs, and Steel</title>
        <author>Jared Diamond</author>
        <date>2005</date>
        <ISBN>0-393-06131-0</ISBN>
        <publisher>W. W. Norton &amp; Company, Ltd.</publisher>
        <cost currency="USD">24.99</cost>
        <cost currency="CAD">31.00</cost>
    </book>
    <book>
        <title>Economics in One Lesson</title>
        <author>Henry Hazlitt</author>
        <date>1946</date>
        <ISBN>0-517-54823-2</ISBN>
        <publisher>Three Rivers Press</publisher>
        <cost currency="USD">11.00</cost>
        <cost currency="CAD">17.00</cost>
    </book>
    <book>
        <title>How to Read a Book</title>
        <author>Mortimer J. Adler</author>
        <author>Charles Van Doren</author>
        <date>1940</date>
        <ISBN>0-671-21280-x</ISBN>
        <publisher>Simon &amp; Schuster, Inc.</publisher>
        <cost currency="USD">15.00</cost>
        <cost currency="CAD">23.00</cost>
    </book>
    <book>
        <title>Don't Make Me Think</title>
        <author>Steve Krug</author>
        <date>2006</date>
        <ISBN>0-321-34475-8</ISBN>
        <publisher>New Riders</publisher>
        <cost currency="USD">40.00</cost>
        <cost currency="CAD">44.00</cost>
        <cost currency="GPB">28.99</cost>
    </book>
    <book>
        <title>Bulletproof Ajax</title>
        <author>Jeremy Keith</author>
        <date>2007</date>
        <ISBN>0-321-47266-7</ISBN>
        <publisher>New Riders</publisher>
        <cost currency="USD">34.99</cost>
        <cost currency="CAD">43.99</cost>
        <cost currency="GPB">24.99</cost>
    </book>
</bookstore>

/Roger



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