| Author |
Adding <pre> to an xml file
|
JayaSiji Gopal
Ranch Hand
Joined: Sep 27, 2004
Posts: 303
|
|
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.
|
SCJP 1.4, SCWCD 1.4<br /> <br />Thanks in advance!<br />Jayashree.
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16487
|
|
|
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
Joined: Sep 27, 2004
Posts: 303
|
|
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
Bartender
Joined: Oct 14, 2005
Posts: 16487
|
|
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
Joined: Sep 27, 2004
Posts: 303
|
|
|
yes precisely. this is not only to save lot of code change, but is also shared by another application.
|
 |
 |
|
|
subject: Adding <pre> to an xml file
|
|
|