469,326 Members | 1,320 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,326 developers. It's quick & easy.

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

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
Mar 12 '09 #1
18 6116
Dormilich
8,651 Expert Mod 8TB
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.....
Mar 12 '09 #2
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.

@Dormilich
Mar 12 '09 #3
Dormilich
8,651 Expert Mod 8TB
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'] ???
Mar 12 '09 #4
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.

@Dormilich
Mar 12 '09 #5
Dormilich
8,651 Expert Mod 8TB
and why don't you change the text in the XML from the start?
Mar 12 '09 #6
Could you please explain me clearly. i didn't get you properly

@Dormilich
Mar 12 '09 #7
Dormilich
8,651 Expert Mod 8TB
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
Mar 12 '09 #8
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.
Mar 12 '09 #9
Dormilich
8,651 Expert Mod 8TB
then you will need a reverse XSLT stylesheet where you may have to feed the unused parts of the original XML (if any).
Mar 12 '09 #10
Could you pelase explain with an example
Mar 12 '09 #11
Dormilich
8,651 Expert Mod 8TB
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)
Mar 12 '09 #12
i think we can not go with this solution.

Any other solution please
Mar 12 '09 #13
Dormilich
8,651 Expert Mod 8TB
@Dormilich
what about this one?
Mar 12 '09 #14
All teh xml files will be very complex and large files. we can not bring reverse xslt concept here.
Mar 12 '09 #15
Dormilich
8,651 Expert Mod 8TB
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).
Mar 12 '09 #16
sorry i didn't get you properly
Mar 12 '09 #17
Dormilich
8,651 Expert Mod 8TB
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.
Mar 12 '09 #18
jkmyoung
2,057 Expert 2GB
@malathib
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.
Mar 12 '09 #19

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Federico | last post: by
3 posts views Thread by Kevin Brown | last post: by
reply views Thread by =?Utf-8?B?UHJhc2hhbnQgQw==?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.