XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
1200+ fellow developers rate and compare features of the top IDEs, like Visual Studio, Eclipse, RAD, Delphi and others, across 13 categories. Enjoy this FREE Download of the IDE User Satisfaction Study by Evans Data Corporation. Download Now!
  #1  
Old July 24th, 2003, 10:00 AM
Wolfgar Wolfgar is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 13 Wolfgar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
New to XML

Hello all.

I am new to XML and am working on a project at work. A client is going to start sending us an XML file and I need to extract the data from this file and insert it into a database. It will then be viewed by HTML/Webspeed programs.

I have a book on learning XML and it seems to document the process of transormation fairly clear except for one par: It skips how to link a document to be transformed to the "template".

What I could really use is a simple, real-life example on how to take an XML file and "parse out the data".

The file structure is set up like this:

<orders>
<order>
<item />
<item />
<item />
</order>
</orders>

I need to take the values from each of the attributes in "item" and create the records in the database.

Currently I am trying to create an XSLT file that will transform the XML file (experimenting by changing to HTML file), but I don't know how to "link" them together....

Any help would be greatly appreciated....

Reply With Quote
  #2  
Old July 24th, 2003, 10:14 AM
tank80's Avatar
tank80 tank80 is offline
php-oriented object
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: 0x9832053
Posts: 173 tank80 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 24 m 49 sec
Reputation Power: 7
Send a message via ICQ to tank80
simply add a processing instruction after the xml declaration

Code:
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="myStyle.xsl"?>
<firstNode>
....
</firstNode>

Last edited by tank80 : July 24th, 2003 at 10:20 AM.

Reply With Quote
  #3  
Old July 24th, 2003, 10:25 AM
Wolfgar Wolfgar is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 13 Wolfgar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally posted by tank80
simply add a processing instruction after the xml declaration

Code:
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="myStyle.xsl"?>
<firstNode>
....
</firstNode>


OK, so you are saying to put that line of code into the XML file, right? Then, when I "execute" the XML file (open in browser), it will format based on the template?

Reply With Quote
  #4  
Old July 24th, 2003, 11:22 AM
tank80's Avatar
tank80 tank80 is offline
php-oriented object
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: 0x9832053
Posts: 173 tank80 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 24 m 49 sec
Reputation Power: 7
Send a message via ICQ to tank80
exactly like that

Reply With Quote
  #5  
Old July 24th, 2003, 11:29 AM
Wolfgar Wolfgar is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 13 Wolfgar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I tried that and am getting the same results.

The XML file, before opening in browser, is just normal looking code. When I open in a browser, the text turn red, the values of atts get bold, the elements take on the "+" and "-" signs to expand and contract.

But, the effects that are in my .xsl file template are not applied....

Reply With Quote
  #6  
Old July 24th, 2003, 11:44 AM
Wolfgar Wolfgar is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 13 Wolfgar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
For example, the following code:

?xml version="1.0" standalone="yes" ?>
<?xml-stylesheet type="text/xml" href="e:\ECOM\newstyle.xsl"?>
<dean>
<reed name="Dean" lname="Reed" address="Latrobe" />
<reed fname="Dean" lname="reed" address="Latrobe" />
</dean>

is normal in an editor, but when I open in browser, the the tags turn red and <dean> is expandable/contractable.

Both this file AND the newstyle.xsl are in the same directory. The .xsl file is this:

<?xml version="1.0" standalone="yes" ?>
<xsl:stylesheet id="dean"
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="dean">
<html>
<body>
<h1>Orders</h1>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

When I open the xml file in a browser, I should display the values of "dean" in <h1></h1> type font, right?

Maybe I am all twisted around..

Reply With Quote
  #7  
Old July 24th, 2003, 11:46 AM
tank80's Avatar
tank80 tank80 is offline
php-oriented object
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: 0x9832053
Posts: 173 tank80 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 24 m 49 sec
Reputation Power: 7
Send a message via ICQ to tank80
try putting an additional node into your stylesheet that specifies the output format.
Code:
<xsl:stylesheet ... >
  <xsl:output method="html"/>

   <!-- your stylesheet here -->

</xsl:stylesheet>


EDIT: damn smilies... the is "colon o"

Reply With Quote
  #8  
Old July 24th, 2003, 11:50 AM
Wolfgar Wolfgar is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 13 Wolfgar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Actually, I am getting this error when I open the xsl file in browser:

The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.


--------------------------------------------------------------------------------

Only one top level element is allowed in an XML document. Error processing resource 'file:///E:/ECOM/newstyle.xsl'. Line 3, Position 2

<xsl:stylesheet id="dean"

Reply With Quote
  #9  
Old July 24th, 2003, 11:52 AM
Wolfgar Wolfgar is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 13 Wolfgar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
NM that last post, I put the output statement under the stylesheet statement and it was ok.

I still don't get HTML output though...

Reply With Quote
  #10  
Old July 24th, 2003, 11:54 AM
tank80's Avatar
tank80 tank80 is offline
php-oriented object
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: 0x9832053
Posts: 173 tank80 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 24 m 49 sec
Reputation Power: 7
Send a message via ICQ to tank80
sorry...saw your latest post just now

if you want to output the nodes inside "dean" the xls should be written like this:
Code:
<?xml version="1.0" standalone="yes" ?> 
<xsl:stylesheet id="dean" version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:output method="html"/>
<xsl:template match="dean"> 
<html> 
<body> 
<h1>Orders</h1>
<xsl:for-each select="reed">
    <!-- this outputs the attribute "address" -->
    <xsl:value-of select="@address"/><br>
</xsl:for-each>
</body> 
</html> 
</xsl:template> 

<xsl:template match="/">
    <xsl:apply-templates/> 
</xsl:template>
</xsl:stylesheet> 

Reply With Quote
  #11  
Old July 24th, 2003, 12:02 PM
Wolfgar Wolfgar is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 13 Wolfgar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Here is the code.

XSL file:
<?xml version="1.0" standalone="yes" ?>
<xsl:stylesheet id="dean" version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsloutput method="html"/>
<xsl:template match="dean">
<html>
<body>
<h1>Test</h1>
<xsl:for-each select="reed">
<!-- this outputs the attribute "address" -->
<xsl:value-of select="@address"/><br></br>
</xsl:for-each>
</body>
</html>
</xsl:template>

<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>

XML File.
<?xml version="1.0" standalone="yes" ?>
<?xml-stylesheet type="text/xml" href="e:\ECOM\newstyle.xsl"?>
<test>
<dean>
<reed name="Dean" lname="Reed" address="Latrobe" />
<reed fname="Dean" lname="reed" address="Latrobe" />
</dean>
</test>

Again, both files are in the same directory and when I open up the XML file in a browser, all I see is the exapandable/contractable elements/sub-elements-atts....

Reply With Quote
  #12  
Old July 24th, 2003, 12:03 PM
Wolfgar Wolfgar is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 13 Wolfgar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
It is as though the XML file is not "seeing" the xsl file....

Reply With Quote
  #13  
Old July 24th, 2003, 12:12 PM
tank80's Avatar
tank80 tank80 is offline
php-oriented object
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: 0x9832053
Posts: 173 tank80 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 24 m 49 sec
Reputation Power: 7
Send a message via ICQ to tank80
xml file:
Code:
<?xml version="1.0"?> 
<?xml-stylesheet type="text/xsl" href="e:\ECOM\newstyle.xsl"?> 
<test> 
 <dean> 
  <reed name="Dean" lname="Reed" address="Latrobe" /> 
  <reed fname="Dean" lname="reed" address="Latrobe" /> 
 </dean> 
</test>


xsl file:
Code:
<?xml version="1.0"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
 <xsl:output method="html"/> 
 <xsl:template match="dean"> 
  <html> 
   <body> 
    <h1>Test</h1> 
    <xsl:for-each select="reed"> 
     <!-- this outputs the attribute "address" --> 
     <xsl:value-of select="@address"/><br></br> 
    </xsl:for-each> 
   </body> 
  </html> 
 </xsl:template> 

 <xsl:template match="/"> 
  <xsl:apply-templates/> 
 </xsl:template> 
</xsl:stylesheet> 


tested and works....maybe an issue with the browser? which version are you using?

Reply With Quote
  #14  
Old July 24th, 2003, 12:16 PM
Wolfgar Wolfgar is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 13 Wolfgar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I am using IE 5.0. I can upgrade to 5.5, but I was downgraded from 6.0 so 5.5 is as high as I can go (company rules).

What output did you get?

Reply With Quote
  #15  
Old July 24th, 2003, 01:24 PM
tank80's Avatar
tank80 tank80 is offline
php-oriented object
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: 0x9832053
Posts: 173 tank80 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 24 m 49 sec
Reputation Power: 7
Send a message via ICQ to tank80
sorry for the late...

i have this output:

Test
Latrobe
Latrobe

i don't know if IE 5.x can transform xml documents with xsl...IE 6 is working. Is that a project requirement?

Last edited by tank80 : July 24th, 2003 at 01:28 PM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > New to XML


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread: