Search code examples
xmlxquerybasex

How to print data without the tag on basex?


I need to display the data of a the xquery below without the tags,so if you can help me out I would greatly appreciate it. How you can notice I already have the query.

 (: Output the customer names of each pair of customers who are associated with the same 
    rep. There should not be any duplicate reversed pair and no customer be paired with the 
    same customer.:)
    
    <result>
      {
        for $customer1 in doc ("../premiere/Customer.xml")//Customer,
            $customer2 in doc ("../premiere/Customer.xml")//Customer
        where  $customer1/RepNum =  $customer2/RepNum and $customer1/CustomerNum <  $customer2/CustomerNum
        order by $customer1/CustomerName
        return 
        <pair>
         "{$customer1/CustomerName}"
         "{$customer2/CustomerName}"
        </pair>
    
      }
    </result>

The output of the query is:

    <result>
  <pair>
     "<CustomerName>Al's Appliance and Sport</CustomerName>"
     "<CustomerName>Kline's</CustomerName>"
    </pair>
  <pair>
     "<CustomerName>Al's Appliance and Sport</CustomerName>"
     "<CustomerName>All Season</CustomerName>"
    </pair>
    .
    . 
    .
  <pair>
     "<CustomerName>The Everything Shop</CustomerName>"
     "<CustomerName>Deerfield's Four Seasons</CustomerName>"
    </pair>
</result>

My output must be:

<results>
  <pair>Al's Appliance and Sport - Kline's</pair>
  <pair>Al's Appliance and Sport - All Season</pair>
  <pair>Bargains Galore - Johnson's Department Store</pair>
  <pair>Brookings Direct - The Everything Shop</pair>
  <pair>Brookings Direct - Lee's Sport and Appliance</pair>
  <pair>Brookings Direct - Deerfield's Four Seasons</pair>
  <pair>Ferguson's - Bargains Galore</pair>
  <pair>Ferguson's - Johnson's Department Store</pair>
  <pair>Kline's - All Season</pair>
  <pair>Lee's Sport and Appliance - Deerfield's Four Seasons</pair>
  <pair>The Everything Shop - Lee's Sport and Appliance</pair>
  <pair>The Everything Shop - Deerfield's Four Seasons</pair>
</results>

How do I remove the tags of my output?


Solution

  • Instead of

    <pair>
             "{$customer1/CustomerName}"
             "{$customer2/CustomerName}"
    </pair>
    

    please try the following:

    <pair>{concat(data($customer1/CustomerName), ' - ', data($customer2/CustomerName))}</pair>