How to preserve XML tags after xml to html transformation using xslt | Newbie | | Join Date: Mar 2009
Posts: 22
| | |
Hi,
while trasforming xml to html using xslt, i dont want to lose xml tags.I want to preserve it.
After transforming to html and displaying in browser and if you are right clicking and viewing the source, xml tags will be there as it is but it will display teh content as html in browser. But after transforming, when i am displaying in text editor, the xml tags are getting lost.
Could anybody help me in this regard.
Regards,
Malathi
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 4,300
| | | re: How to preserve XML tags after xml to html transformation using xslt
why do you want the original XML code to be available after XSLT? (besides the fact, that your HTML document will be invalid...)
maybe the text editor just ignores the XML.....
| | Newbie | | Join Date: Mar 2009
Posts: 22
| | | re: How to preserve XML tags after xml to html transformation using xslt
After embedding the transformed html in text editor, if i will modify the content
and save it, it has to save the changes again to the same xml file. If xml tags are getting preserved, we no need to do any more work on that. thats all my work will be done. Quote:
Originally Posted by Dormilich why do you want the original XML code to be available after XSLT? (besides the fact, that your HTML document will be invalid...)
maybe the text editor just ignores the XML..... |  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 4,300
| | | re: How to preserve XML tags after xml to html transformation using xslt
what kind of changes are that (text changes, structure changes)? maybe a code example could help me understand.
you want to do (basicly)
[xml 1] =(XSLT)=> [html 1] =(editor)=> [html 2] =(?)=> [xml 1'] ???
| | Newbie | | Join Date: Mar 2009
Posts: 22
| | | re: How to preserve XML tags after xml to html transformation using xslt
it can be changes in text, deletion of text, insertion of text.
suppose: in xml file if it is like
<p>This is Malathi</p>
After getting displayed in text editor, i will update Malathi to neelima. so here it has to get changed in appropriate position preserving all the xml tags. Quote:
Originally Posted by Dormilich what kind of changes are that (text changes, structure changes)? maybe a code example could help me understand.
you want to do (basicly)
[xml 1] =(XSLT)=> [html 1] =(editor)=> [html 2] =(?)=> [xml 1'] ??? |  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 4,300
| | | re: How to preserve XML tags after xml to html transformation using xslt
and why don't you change the text in the XML from the start?
| | Newbie | | Join Date: Mar 2009
Posts: 22
| | | re: How to preserve XML tags after xml to html transformation using xslt
Could you please explain me clearly. i didn't get you properly Quote:
Originally Posted by Dormilich and why don't you change the text in the XML from the start? |  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 4,300
| | | re: How to preserve XML tags after xml to html transformation using xslt
I suppose all your data for the HTML document come either from the XML or the XSL (static stuff like the core structure) file.
XML - <?xml version="1.0" ?>
-
<root>
-
<para>This is Malathi</para>
-
</root>
XSL - ...
-
<xsl:template match="para">
-
<p><xsl:value-of select="./text()"/></p>
-
</xsl:template>
-
...
giving you: - ...
-
<p>This is Malathi</p>
-
...
and you change your HTML to - ...
-
<p>This is Neelima</p>
-
...
thus XML should be updated to - <?xml version="1.0" ?>
-
<root>
-
<para>This is Neelima</para>
-
</root>
which you can also do simply by changing Malathi => Neelima in the XML file
| | Newbie | | Join Date: Mar 2009
Posts: 22
| | | re: How to preserve XML tags after xml to html transformation using xslt
First of all let me explain you clearly about my requirement
My application is as follows.
The author will login to out application. He will select a file to edit it.That file will be an xml file. we will display for the author with all the styles and formattings by converting xml file to html using xslt in text editor. so teh author can do text changes, delete text, insert and also he can format. after doing all the required changes, he will click on Save.so that it will saved to teh same xml file at exact positions.
So here if we are preserving the xml tags, it will be easy for us.
The XML file should get converted to HTML using XSL and should get displayed in text editor with one save button.
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 4,300
| | | re: How to preserve XML tags after xml to html transformation using xslt
then you will need a reverse XSLT stylesheet where you may have to feed the unused parts of the original XML (if any).
| | Newbie | | Join Date: Mar 2009
Posts: 22
| | | re: How to preserve XML tags after xml to html transformation using xslt
Could you pelase explain with an example
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 4,300
| | | re: How to preserve XML tags after xml to html transformation using xslt
first, you need to use XHTML (because you can apply XSLT only on XML documents)
very simple example - <?xml version="1.0" encoding="UTF-8" ?>
-
<root>
-
<para>I was here</para>
-
</root>
- <?xml version="1.0" encoding="UTF-8" ?>
-
<xsl:stylesheet version="1.0"
-
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
-
-
<xsl:output
-
method="xml"
-
encoding="utf-8"
-
doctype-public="-//W3C//DTD XHTML 1.1//EN" />
-
-
<xsl:template match="/">
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
-
<head>
-
<title>sample.xml transformed</title>
-
</head>
-
<body>
-
<p><xsl:value-of select="para[1]/text()"/></p>
-
</body>
-
</html>
-
</xsl:template>
-
</xsl:stylesheet>
- <?xml version="1.0" encoding="UTF-8" ?>
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
-
<head>
-
<title>sample.xml transformed</title>
-
</head>
-
<body>
-
<p>I was here</p>
-
</body>
-
</html>
the reverse XSLT would be like: - <?xml version="1.0" encoding="UTF-8" ?>
-
<xsl:stylesheet version="1.0"
-
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
-
-
<xsl:output
-
method="xml"
-
encoding="utf-8" />
-
-
<xsl:template match="/">
-
<root>
-
<para><xsl:value-of select="//p[1]/text()"/></para>
-
</root>
-
</xsl:template>
-
</xsl:stylesheet>
needless to say, that the complexity of the reverse stylesheet will skyrocket, as you increase the complexity of the XML and XSL files.
maybe there is a possibility to track the changes, so that you can do a string replace directly in the XML file (requires a script/programm)
| | Newbie | | Join Date: Mar 2009
Posts: 22
| | | re: How to preserve XML tags after xml to html transformation using xslt
i think we can not go with this solution.
Any other solution please
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 4,300
| | | re: How to preserve XML tags after xml to html transformation using xslt Quote:
Originally Posted by Dormilich maybe there is a possibility to track the changes, so that you can do a string replace directly in the XML file (requires a script/programm) what about this one?
| | Newbie | | Join Date: Mar 2009
Posts: 22
| | | re: How to preserve XML tags after xml to html transformation using xslt
All teh xml files will be very complex and large files. we can not bring reverse xslt concept here.
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 4,300
| | | re: How to preserve XML tags after xml to html transformation using xslt
1) I already undestood that
2) you don't need to quote the full previous post, if you don't want to focus on a specific predicate therein (where you would only quote that).
| | Newbie | | Join Date: Mar 2009
Posts: 22
| | | re: How to preserve XML tags after xml to html transformation using xslt
sorry i didn't get you properly
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 4,300
| | | re: How to preserve XML tags after xml to html transformation using xslt
you could write a programm, that remembers which text has been changed and then looks for that text in the xml file and replaces it with the new text.
you could also try to map the elements in the html and xml file (like: first <para> becomes first <p>) and replace the text based on this.
| | Moderator | | Join Date: Mar 2006
Posts: 1,104
| | | re: How to preserve XML tags after xml to html transformation using xslt Quote:
Originally Posted by malathib The author will login to out application. He will select a xml file to edit. When you say application, is it an online text editing application?
If not, why not just an ftp site with read/write permissions?
Current thoughts seem overcomplicated. Sounds like sharepoint.
|  | | | | Forums
Visit our community forums for general discussions and latest on Bytes
/bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 229,155 network members.
|