Skip to main content

Creating xml based on html using xslt in java



Please help me i am doing project of file conversion that is converting xml to html using xsl in java and also i need to convert html to xml using the xsl. my first process is got over.but i structed in second part of conversion.. Is there is any possibility to do that conversion.I will tell you the exact flow of the first process...





This is my sample xml file: tabl.xml:







<?xml version="1.0" encoding="utf-8"?>

<?xml-stylesheet type="text/xml" href="testxsl.xsl"?>

<mainpara>

<epigraph>

<para>Though successful research demands a deep

<emphasis role="italic">trained</emphasis>

<emphasis role="italic">taught</emphasis> to regard.

</para>

<para>Kuhn (1976, p. 66)</para>

</epigraph>

<blockquote role="extract">

<para>Though successful research demands a deep commitment to the status quo.

<emphasis role="italic">trained</emphasis>

<emphasis role="italic">taught</emphasis>

</para>

</blockquote>

</mainpara>







This is my sample xsl file:





testme.xsl







<?xml version="1.0"?>

<xsl:stylesheet version="1.0"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="mainpara">

<html>

<body>

<xsl:apply-templates/>

</body>

</html>

</xsl:template>



<xsl:template match="epigraph">

<div>

<xsl:apply-templates/>

</div>

</xsl:template>



<xsl:template match="para">

<p>

<xsl:apply-templates/>

</p>

</xsl:template>



<xsl:template match="blockquote">

<b>

<xsl:apply-templates/>

</b>

</xsl:template>

</xsl:stylesheet>







This is my sample java file:





Main.java







import java.io.File;

import java.io.InputStream;

import javax.xml.transform.Transformer;

import javax.xml.transform.TransformerFactory;

import javax.xml.transform.stream.StreamResult;

import javax.xml.transform.stream.StreamSource;



public class Main {





public static void simpleTransform(String sourcePath, String xsltPath,

String resultDir) {



TransformerFactory tFactory = TransformerFactory.newInstance();

try {

Transformer transformer =

tFactory.newTransformer(new StreamSource(new File(xsltPath)));



transformer.transform(new StreamSource(new File(sourcePath)),

new StreamResult(new File(resultDir)));



} catch (Exception e) {

e.printStackTrace();

}

}



public static void main(String[] args) {





System.setProperty("javax.xml.transform.TransformerFactory",

"net.sf.saxon.TransformerFactoryImpl");



simpleTransform("E:/bh/tabl.xml","E:/bh/testme.xsl", "E:/bh/me.html");

//simpleTransform("E:/bh/me.html","E:/bh/11111.xsl","E:/bh/tab.xml" ); //This is i need



}

}







This is my generated html file:







<html>

<body>

<div>



<p>Though successful research demands a deep commitment to the status quo, innovation

</p>



<p>Kuhn (1976, p. 66)</p>



</div>

<b>



<p>Though successful research demands a deep commitment to the status quo

</p>

</b>



</body>

</html>







Now i will edit this html file after edited this html file i need to convert this again to the xml file or xhtml file that is i need the reverse process. I think it is possible only by modifying the xsl. Is it possible to create the xsl based on that html.If i created that xsl file then i pass that xsl file in the above java program( i commented that line in the main java program).So i have to create that xsl file.





Please help me.. I need your help..





Thanks in advance


Comments

Popular posts from this blog

[韓日関係] 首相含む大幅な内閣改造の可能性…早ければ来月10日ごろ=韓国

div not scrolling properly with slimScroll plugin

I am using the slimScroll plugin for jQuery by Piotr Rochala Which is a great plugin for nice scrollbars on most browsers but I am stuck because I am using it for a chat box and whenever the user appends new text to the boxit does scroll using the .scrollTop() method however the plugin's scrollbar doesnt scroll with it and when the user wants to look though the chat history it will start scrolling from near the top. I have made a quick demo of my situation http://jsfiddle.net/DY9CT/2/ Does anyone know how to solve this problem?

Why does this javascript based printing cause Safari to refresh the page?

The page I am working on has a javascript function executed to print parts of the page. For some reason, printing in Safari, causes the window to somehow update. I say somehow, because it does not really refresh as in reload the page, but rather it starts the "rendering" of the page from start, i.e. scroll to top, flash animations start from 0, and so forth. The effect is reproduced by this fiddle: http://jsfiddle.net/fYmnB/ Clicking the print button and finishing or cancelling a print in Safari causes the screen to "go white" for a sec, which in my real website manifests itself as something "like" a reload. While running print button with, let's say, Firefox, just opens and closes the print dialogue without affecting the fiddle page in any way. Is there something with my way of calling the browsers print method that causes this, or how can it be explained - and preferably, avoided? P.S.: On my real site the same occurs with Chrome. In the ex