473,379 Members | 1,281 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

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 6500
Dormilich
8,658 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,658 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,658 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,658 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,658 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,658 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,658 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,658 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,658 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

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

Similar topics

1
by: Igor | last post by:
Is there any way to resort and xml document using xslt based on element position. For example if I have xml like this: <root> <element> 1st thing </element> <element> 2nd thing </element>...
0
by: Federico | last post by:
Hi all, I don't know if this topic is perhaps a little bit off-topic, anyway I have a strange problem in transforming an XML file in an HTML file using XSLT form a Java program written with...
3
by: Kevin Brown | last post by:
Is there anyway to generate this type of resulting HTML table from this XML using XSLT? Basically I need to be able to consult 2 trees of data to generate the HTML, but I have not been able to...
1
by: MORALBAROMETER | last post by:
Hi all, I want to update MULTIPLE elements of an HTML page using Ajax. for this reason i my response is an xml document. I want to use XSL at the client side to update these elements. How can i...
1
by: patelgaurav85 | last post by:
Hi, I want to convert xml in one format into another xml format shown below Input xml : <Name> <Name1> <Name11>Name11</Name11> <Name12>Name12</Name12>
0
by: =?Utf-8?B?UHJhc2hhbnQgQw==?= | last post by:
-- Regards, Prashant C
7
by: pivote | last post by:
I'm trying to transform a XML file to another XML file. The first file must describe what I want to say in a more abstract way than the second. But in order to do the transformation, I need an...
3
sujathaeeshan
by: sujathaeeshan | last post by:
hi all, here is xml file..... <root> <Xmltype> <owner NAME="Legal Entity 1"></owner> <LegalEntity NAME="Legal Entity 1"></LegalEntity> <lob NAME="Line Of Business 1"></lob>...
5
by: anand18101984 | last post by:
I am having an XML like below, <SECT1><TITLE>Title1</TITLE><PARA>Line1<BR/>Line2<BR/>Line3<BR/>Line4<BR/>Line5</PARA></SECT1> I want to convert this into another XML in the following format,...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.