Connecting Tech Pros Worldwide Help | Site Map

How to preserve XML tags after xml to html transformation using xslt

  #1  
Old March 12th, 2009, 12:12 PM
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
  #2  
Old March 12th, 2009, 12:18 PM
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,485
Provided Answers: 9

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.....
  #3  
Old March 12th, 2009, 12:37 PM
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 View Post
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.....
  #4  
Old March 12th, 2009, 12:57 PM
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,485
Provided Answers: 9

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'] ???
  #5  
Old March 12th, 2009, 01:13 PM
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 View Post
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'] ???
  #6  
Old March 12th, 2009, 01:14 PM
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,485
Provided Answers: 9

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?
  #7  
Old March 12th, 2009, 01:17 PM
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 View Post
and why don't you change the text in the XML from the start?
  #8  
Old March 12th, 2009, 01:27 PM
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,485
Provided Answers: 9

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
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" ?>
  2. <root>
  3.     <para>This is Malathi</para>
  4. </root>
XSL
Expand|Select|Wrap|Line Numbers
  1. ...
  2. <xsl:template match="para">
  3. <p><xsl:value-of select="./text()"/></p>
  4. </xsl:template>
  5. ...
giving you:
Expand|Select|Wrap|Line Numbers
  1. ...
  2. <p>This is Malathi</p>
  3. ...
and you change your HTML to
Expand|Select|Wrap|Line Numbers
  1. ...
  2. <p>This is Neelima</p>
  3. ...
thus XML should be updated to
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" ?>
  2. <root>
  3.     <para>This is Neelima</para>
  4. </root>
which you can also do simply by changing Malathi => Neelima in the XML file
  #9  
Old March 12th, 2009, 01:37 PM
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.

Last edited by Dormilich; March 12th, 2009 at 01:41 PM. Reason: removed full quote
  #10  
Old March 12th, 2009, 01:43 PM
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,485
Provided Answers: 9

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).
  #11  
Old March 12th, 2009, 01:48 PM
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

Last edited by Dormilich; March 12th, 2009 at 01:49 PM. Reason: removed full quote
  #12  
Old March 12th, 2009, 02:13 PM
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,485
Provided Answers: 9

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
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <root>
  3.   <para>I was here</para>
  4. </root>
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <xsl:stylesheet version="1.0"
  3.     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  4.  
  5. <xsl:output
  6.     method="xml"
  7.     encoding="utf-8"
  8.     doctype-public="-//W3C//DTD XHTML 1.1//EN" />
  9.  
  10. <xsl:template match="/">
  11. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  12.     <head>
  13.         <title>sample.xml transformed</title>
  14.     </head>
  15.     <body>
  16.          <p><xsl:value-of select="para[1]/text()"/></p>
  17.     </body>
  18. </html>
  19. </xsl:template>
  20. </xsl:stylesheet>
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  4.     <head>
  5.         <title>sample.xml transformed</title>
  6.     </head>
  7.     <body>
  8.         <p>I was here</p>
  9.     </body>
  10. </html>
the reverse XSLT would be like:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <xsl:stylesheet version="1.0"
  3.     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  4.  
  5. <xsl:output
  6.     method="xml"
  7.     encoding="utf-8" />
  8.  
  9. <xsl:template match="/">
  10. <root>
  11.   <para><xsl:value-of select="//p[1]/text()"/></para>
  12. </root>
  13. </xsl:template>
  14. </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)
  #13  
Old March 12th, 2009, 02:29 PM
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

Last edited by Dormilich; March 12th, 2009 at 02:30 PM. Reason: removed full quote
  #14  
Old March 12th, 2009, 02:31 PM
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,485
Provided Answers: 9

re: How to preserve XML tags after xml to html transformation using xslt


Quote:
Originally Posted by Dormilich View Post
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?
  #15  
Old March 12th, 2009, 02:35 PM
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.

Last edited by Dormilich; March 12th, 2009 at 02:36 PM. Reason: removed full quote again
  #16  
Old March 12th, 2009, 02:38 PM
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,485
Provided Answers: 9

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).
  #17  
Old March 12th, 2009, 02:41 PM
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
  #18  
Old March 12th, 2009, 02:45 PM
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,485
Provided Answers: 9

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.
  #19  
Old March 12th, 2009, 04:03 PM
Moderator
 
Join Date: Mar 2006
Posts: 1,103

re: How to preserve XML tags after xml to html transformation using xslt


Quote:
Originally Posted by malathib View Post
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.
Reply

Tags
preservexmltags