• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Adding <pre> to an xml file

 
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes precisely. this is not only to save lot of code change, but is also shared by another application.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic