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
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
+ XSLT Help and Discussion (7625)
- XQuery Help and Discussion (2017)
-> + Issue with Processing Instruct... (2)
-> + problem converting json to XML... (2)
-> + Problem base64 decoding string... (3)
-> + Problems posting multipart for... (5)
-> + trouble with download of price... (2)
-> + Problem with http-post not bei... (3)
-> + path problem, xps_file:writeAl... (9)
-> + Xquery update support? (2)
-> + problem with Stylus studio try... (5)
-> + adding dtd reference to xml ou... (4)
-> + xquery escaping ambarsand when... (3)
-> + Whitespace problem when return... (5)
-> + Problem with namespace prefix ... (5)
-> - Sending via SFTP returns unexp... (1)
-> + Query and Sftp clent (4)
-> + xquery and try - catch (3)
-> + Query + ddtek:http-post optio... (5)
-> + Example files referenced in do... (3)
-> + Automatic Error Detection and ... (3)
-> + Working with result of ddtek:h... (2)
-- [1-20] [21-40] [41-60] Next
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
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

   
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.