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: I can't seem to get my xml "re-arranged" properly.
Author: Doug Lundin
Date: 27 Nov 2006 05:39 PM
I have been trying to figure out this problem. I can't seem to get my xml "re-arranged" properly.

Here is what I've done:

[1] Created an XHTML file from Yahoo using HTML to XML wizard and Tidy adapter

[2] Created testcase.xquery file:
declare namespace a = "http://www.w3.org/1999/xhtml";

<Gainers>
<CompanyName>
{/a:html/a:body[1]/a:div[1]/a:div[3]/a:div[3]/a:div[2]/a:div[2]/a:table[1]/a:tbody[1]/a:tr/a:td[2]/normalize-space()}
</CompanyName>
<Ticker>
{/a:html/a:body[1]/a:div[1]/a:div[3]/a:div[3]/a:div[2]/a:div[2]/a:table[1]/a:tbody[1]/a:tr/a:td[1]/a:b[1]/a:a[1]/normalize-space()}
</Ticker>
<LastTradePrice>
{/a:html/a:body[1]/a:div[1]/a:div[3]/a:div[3]/a:div[2]/a:div[2]/a:table[1]/a:tbody[1]/a:tr/a:td[3]/a:b[1]/normalize-space()}
</LastTradePrice>
</Gainers>

[3] When I run the xquery I get (minimally formatted):
<Gainers>
<CompanyName>CONOLOG CORP TARGETED GENETICS CP MICROWAVE FILTER C</CompanyName>
<Ticker>CNLG TGEN MFCO</Ticker>
<LastTradePrice>3.68 6.30 1.55</LastTradePrice>
</Gainers>


[4] I would like to see:
<Gainers>
<CompanyName>CONOLOG CORP</CompanyName>
<CompanyName>TARGETED GENETICS CP</CompanyName>
<CompanyName>MICROWAVE FILTER C</CompanyName>
<Ticker>CNLG</Ticker>
<Ticker>TGEN</Ticker>
<Ticker>MFCO</Ticker>
<LastTradePrice>3.68</LastTradePrice>
<LastTradePrice>6.30</LastTradePrice>
<LastTradePrice>1.55</LastTradePrice>
</Gainers>


[5] Is this possible for the output?:
<Gainers>
<CompanyName>CONOLOG CORP</CompanyName>
<Ticker>CNLG</Ticker>
<LastTradePrice>3.68</LastTradePrice>
<CompanyName>TARGETED GENETICS CP</CompanyName>
<Ticker>TGEN</Ticker>
<LastTradePrice>6.30</LastTradePrice>
<CompanyName>MICROWAVE FILTER C</CompanyName>
<Ticker>MFCO</Ticker>
<LastTradePrice>1.55</LastTradePrice>
</Gainers>


Thank you
Doug

Postnext
Ivan PedruzziSubject: I can't seem to get my xml
Author: Ivan Pedruzzi
Date: 27 Nov 2006 05:50 PM

Hi Doug,

Could you please post the input document?



Ivan Pedruzzi
Stylus Studio Team

Postnext
Doug LundinSubject: I can't seem to get my xml
Author: Doug Lundin
Date: 27 Nov 2006 05:54 PM
Here is the input doc


Unknowntestcase(1).xml
testcase.xml

Unknowntestcase.xquery
testcase.xquery

Postnext
Ivan PedruzziSubject: I can't seem to get my xml
Author: Ivan Pedruzzi
Date: 27 Nov 2006 06:13 PM

Try this

Ivan Pedruzzi
Stylus Studio Team


Documenttestcase(1).xquery

Postnext
Doug LundinSubject: I can't seem to get my xml
Author: Doug Lundin
Date: 27 Nov 2006 06:20 PM
Fantastic turnaround - thanks!

Postnext
Doug LundinSubject: I can't seem to get my xml
Author: Doug Lundin
Date: 28 Nov 2006 07:15 AM
Ok, now I've fiddled around trying to get the data into its end-state:
<Gainers>
<CompanyName>CONOLOG CORP</CompanyName>
<Ticker>CNLG</Ticker>
<LastTradePrice>3.68</LastTradePrice>
<CompanyName>TARGETED GENETICS CP</CompanyName>
<Ticker>TGEN</Ticker>
<LastTradePrice>6.30</LastTradePrice>
<CompanyName>MICROWAVE FILTER C</CompanyName>
<Ticker>MFCO</Ticker>
<LastTradePrice>1.55</LastTradePrice>
</Gainers>

Is this a job for XSLT?

Posttop
Ivan PedruzziSubject: I can't seem to get my xml
Author: Ivan Pedruzzi
Date: 28 Nov 2006 07:43 AM
declare namespace a = "http://www.w3.org/1999/xhtml";

<Gainers >
{
for $t at $pos in /a:html/a:body[1]/a:div[1]/a:div[3]/a:div[3]/a:div[2]/a:div[2]/a:table[1]/a:tbody[1]/a:tr
return
(
<CompanyName>{$t/a:td[2]/text()}</CompanyName>,
<Ticker>{$t/a:td[1]/a:b[1]/a:a[1]/text()}</Ticker>,
<LastTradePrice>{$t/a:td[3]/a:b[1]/text()}</LastTradePrice>
)
}
</Gainers>


Ivan Pedruzzi
Stylus Studio Team

 
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.