Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Adding <pre> to an xml file

 
JayaSiji Gopal
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an xml file as follows:



I need to transform the text in body tag and append the pre tag...something like:



I have tried something like this:


This works fine. However, this is actually copying the xml structure first in memory and then recreating the entire xml.
Is there a way in xslt i could navigate to the required node and append <pre> within the body tag. Essentially i am thinking if there is a clean way to do it.
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure, but the way to think of it is not as "inserting tags". The way to think of it is, you're replacing the text child of the "body" element by a "pre" element with that text as its only child.
 
JayaSiji Gopal
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul,

Thank you for the reply. Could you point me to some examples which would help me do this.
Also, i dont want to add a tag.

I want to add as text inside the body tag. It would be an awful amount of existing java code change if i add it as a tag. that is why.
i tried searching for xslt add text...but didnt find any.
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay. So what you want to end up with is this:

And the way to do that is to replace the text with this:


That's different than inserting a <pre> element, so I don't quite understand why you chose to do something different (and possibly wrong) just to save making a lot of code changes. However perhaps you really do need the <pre> tags as text rather than as markup.
 
JayaSiji Gopal
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes precisely. this is not only to save lot of code change, but is also shared by another application.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic