| | |
XML to XML transformation
Please support our XML, XSLT and XPATH advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2009
Posts: 9
Reputation:
Solved Threads: 0
I am new to XSLT. I am trying to transform one XML document to another. My first step is to try an do a really simple example. I want to see the results to my simple example in a browser, but neither IE7 or Firefox is not returning the results I expect. My XML is:
I simply want to produce a simple output of:
My XSLT is:
IE7 says
To top it all off, my java program wont compile the style sheet. I want to get this simple sample going so I can move on to the actual XML files that I wish to transform to update databases. Please help, I must be missing something within the XSL.
XML, XSLT and XPATH Syntax (Toggle Plain Text)
<?xml version="1.0" encoding="ISO-8859-1"?> <?xml-stylesheet type="text/xsl" href="test.xsl"?> <catalog> <cd> <title>Empire Burlesque</title> <artist>Bob Dylan</artist> <country>USA</country> <company>Columbia</company> <price>10.90</price> <year>1985</year> </cd> <cd> <title>Hide your heart</title> <artist>Bonnie Tyler</artist> <country>UK</country> <company>CBS Records</company> <price>9.90</price> <year>1988</year> </cd> </catalog>
I simply want to produce a simple output of:
XML, XSLT and XPATH Syntax (Toggle Plain Text)
<root> <singer>Bob Dylan</singer> <singer>Bonnie Tyler</singer> </root>
My XSLT is:
XML, XSLT and XPATH Syntax (Toggle Plain Text)
<?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:template match="/"> <xsl:element name="root"> <xsl:for-each select="catalog/cd"> <xsl:element name="singer"> <xsl:value-of select="artist" /> </xsl:element> <br /> </xsl:for-each> </xsl:template> </xsl:stylesheet>
IE7 says
Access is denied. Error processing resource... Firefox displays all the data as text (no xml tags).To top it all off, my java program wont compile the style sheet. I want to get this simple sample going so I can move on to the actual XML files that I wish to transform to update databases. Please help, I must be missing something within the XSL.
•
•
Join Date: Oct 2008
Posts: 101
Reputation:
Solved Threads: 5
You are still thinking in terms of procedural languages such as C or Java. Here is how to do it in a declarative language such as XSL.
XML, XSLT and XPATH Syntax (Toggle Plain Text)
<?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:template match="/"> <xsl:element name="root"> <xsl:apply-templates select="catalog/cd/artist"/> </xsl:element> </xsl:template> <xsl:template match="catalog/cd/artist"> <xsl:element name="singer" > <xsl:value-of select="."/> </xsl:element> </xsl:template> </xsl:stylesheet>
•
•
Join Date: Feb 2009
Posts: 9
Reputation:
Solved Threads: 0
Thanks for your reply. I probably am still thinking in terms of precedural languages. I changed my XSL document to what you said, however, IE7 still tells me
Firefox still won't display the data correctly, which is odd.
Is there a security setting on IE?
My Java program indicates that it can't compile the the stylesheet. My code for my program is (only a simple program for testing purposes):
I would appreciate any other feedback/assistance.
Is there a good tutorial for XML transformation? The w3c one seems to focus on transforming to HTML, not to another XML doucment.
'Access is denied. Error Processing resource...<file path> .Firefox still won't display the data correctly, which is odd.
Is there a security setting on IE?
My Java program indicates that it can't compile the the stylesheet. My code for my program is (only a simple program for testing purposes):
Java Syntax (Toggle Plain Text)
import java.io.File; import javax.xml.transform.ErrorListener; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; public class SimpleXMLTransform { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub String inXML = "C:/cdcatalog.xml"; String inXSL = "C:/test.xsl"; String outTXT = "C:/test.xml"; SimpleXMLTransform st = new SimpleXMLTransform(); try { st.transform(inXML,inXSL,outTXT); } catch(TransformerConfigurationException e) { System.err.println("Invalid factory configuration"); System.err.println(e); } catch(TransformerException e) { System.err.println("Error during transformation"); System.err.println(e); } } public void transform(String inXML,String inXSL,String outTXT) throws TransformerConfigurationException, TransformerException { TransformerFactory factory = TransformerFactory.newInstance(); StreamSource xslStream = new StreamSource(inXSL); Transformer transformer = factory.newTransformer(xslStream); transformer.setErrorListener(new MyErrorListener()); StreamSource in = new StreamSource(inXML); StreamResult out = new StreamResult(outTXT); transformer.transform(in,out); System.out.println("The generated XML file is:" + outTXT); } } class MyErrorListener implements ErrorListener { public void warning(TransformerException e) throws TransformerException { show("Warning",e); throw(e); } public void error(TransformerException e) throws TransformerException { show("Error",e); throw(e); } public void fatalError(TransformerException e) throws TransformerException { show("Fatal Error",e); throw(e); } private void show(String type,TransformerException e) { System.out.println(type + ": " + e.getMessage()); if(e.getLocationAsString() != null) System.out.println(e.getLocationAsString()); } }
I would appreciate any other feedback/assistance.
Is there a good tutorial for XML transformation? The w3c one seems to focus on transforming to HTML, not to another XML doucment.
•
•
Join Date: Feb 2009
Posts: 9
Reputation:
Solved Threads: 0
I have got it working now. You are 100% correct. Thankyou for your assistance.
There does seems to be an issue with long file paths. When I copied my documents to c:\tmp, then re-ran my program, it worked. I am still having an issue with IE7 though. When I put the reference in to the xsl in the xml file, IE7 still throws the error previously mentioned.
Does anyone know why IE7 would have an issue with displaying the output?
However, my java program works as expected, and produces the desired result.
There does seems to be an issue with long file paths. When I copied my documents to c:\tmp, then re-ran my program, it worked. I am still having an issue with IE7 though. When I put the reference in to the xsl in the xml file, IE7 still throws the error previously mentioned.
Does anyone know why IE7 would have an issue with displaying the output?
However, my java program works as expected, and produces the desired result.
![]() |
Similar Threads
- How to apply No right click script inhere...? (JavaScript / DHTML / AJAX)
- Regarding xml - html transformation using xslt (XML, XSLT and XPATH)
- XML Transformation using XSLT (XML, XSLT and XPATH)
- Asp+xml+mssql (ASP)
- XML Transformations (XML, XSLT and XPATH)
- Asp.net+xml+ms Sql (ASP.NET)
- updating pages with XML- "forthcoming events info" (RSS, Web Services and SOAP)
Other Threads in the XML, XSLT and XPATH Forum
Views: 2357 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for XML, XSLT and XPATH
api blogger blogging code dataset delete development dynamiccreationofnvariablesinxslt error firstthreecharacterofastringrequired flipbook gdata google html include java link linspire linux microsoft news node openoffice overwrite precedence programming rss serialization standards swf template transform variable w3c web xml xmlnotloading xmlonserver xsl xslt





