|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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.... |
|
#2
|
||||
|
||||
|
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. |
|
#3
|
|||
|
|||
|
Quote:
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? |
|
#4
|
||||
|
||||
|
exactly like that
![]() |
|
#5
|
|||
|
|||
|
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.... |
|
#6
|
|||
|
|||
|
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.. |
|
#7
|
||||
|
||||
|
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" |
|
#8
|
|||
|
|||
|
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" |
|
#9
|
|||
|
|||
|
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... |
|
#10
|
||||
|
||||
|
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>
|
|
#11
|
|||
|
|||
|
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.... |
|
#12
|
|||
|
|||
|
It is as though the XML file is not "seeing" the xsl file....
|
|
#13
|
||||
|
||||
|
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? |
|
#14
|
|||
|
|||
|
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? |
|
#15
|
||||
|
||||
|
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. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > New to XML |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |