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
Doug LundinSubject: Single row to multiple row transformation?
Author: Doug Lundin
Date: 28 Apr 2006 04:19 PM
Hello,

Being new to XQuery, what I am trying to do may be very simple but I don't even have the language to describe it. So, let me explain as concisely as I can. I believe my XQuery mapping is incorrect.

I would like to take three datapoints and, with an XQuery, map them into a new file with three datapoints. But, my XQuery is smashing all three datapoints into a single datapoint. (Data below)

Am I missing a function?

Thanks in advance!
Doug

Here are my data

XML input:
<?xml version="1.0" encoding="utf-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<table>
<tr>
<td>
<ul>
<li><span class="headline"><a href="http://biz.yahoo.com/bw/060201/20060201006257.html?.v=1">SonoSite
Schedules Fourth Quarter and Year-End Financial Release and
Announces Conference Call</a></span>
</li>
<li><span class="headline"><a href="http://biz.yahoo.com/bw/060201/20060201006254.html?.v=1">Sheila
Kelley's S Factor Launches in Encino,
California</a></span>
</li>
<li><span class="headline"><a href="http://biz.yahoo.com/bw/060201/20060201006252.html?.v=1">Pacific
Commerce Bank Announces Appointment of Brian H. Kelley as Chief
Executive Officer</a></span>
</li>
</ul>
</td>
</tr>
</table>
</body>
</html>


xquery:
declare namespace a = "http://www.w3.org/1999/xhtml";
<transform>
<content_url>
{data(/a:html/a:body/a:table/a:tr/a:td/a:ul/a:li/a:span/a:a/@href)}
</content_url>
</transform>


Results of this operation:
<transform>
<content_url>http://biz.yahoo.com/bw/060201/20060201006257.html?.v=1 http://biz.yahoo.com/bw/060201/20060201006254.html?.v=1 http://biz.yahoo.com/bw/060201/20060201006252.html?.v=1</content_url>
</transform>


I am trying to get:
<transform>
<content_url>http://biz.yahoo.com/bw/060201/20060201006257.html?.v=1</content_url>
<content_url>http://biz.yahoo.com/bw/060201/20060201006254.html?.v=1</content_url>
<content_url>http://biz.yahoo.com/bw/060201/20060201006252.html?.v=1</content_url>
</transform>

Postnext
(Deleted User) Subject: Single row to multiple row transformation?
Author: (Deleted User)
Date: 28 Apr 2006 05:00 PM
Hi Doug

You can try this...

declare namespace a = "http://www.w3.org/1999/xhtml";
<transform>
{
for $v in data(/a:html/a:body/a:table/a:tr/a:td/a:ul/a:li/a:span/a:a/@href)
return
<content_url>
{$v}
</content_url>
}
</transform>


Regards
Srini

You can find a quick primer on XQuery at http://www.stylusstudio.com/xquery_primer.html.

Posttop
Doug LundinSubject: Single row to multiple row transformation?
Author: Doug Lundin
Date: 28 Apr 2006 05:11 PM
That did it - thanks!

I'll work through the tutorials now

 
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.