XSLT: convert carriage returns to paragraphs in mixed node while preserving HTML?

EDIT : Sorry, I missed to split text nodes!

EDIT: Sorry, I missed to split text nodes! Most general problem: wraping non empty mixed content lines with p element The problem here is how the input tree provider deals with white space only text nodes. Only Saxon seems to preserve white space only text nodes... Of course, adding xml:space="preserve" in the input, solves the problem for every other XSLT processor.

This stylesheet: With this input (more complex than question): line 1 line 2 line 2 after before line 3 Output: line 1 line 2 line 2 after before line 3 Reduce problem: wrapping non empty text nodes lines and every other node child with p element This stylesheet: With question input sample, output: line 1 line 2 line 3 With my own more complex input (without @xml:space): line 1 line 2 line 2 after before line 3 Output: line 1 line 2 line 2 after before line 3.

Thanks Alejandro, I appreciate your help and I'm glad you considered a more generalized solution. I was worried I had oversimplified the test case after I read your initial reply. I'm going to compare my results with your method against Dimitre's and see which works for me.It's great to see different ways to tackle the problem.

– Casey Sep 17 '10 at 21:34 @Casey: You are wellcome. Ask any doubts! – user357812 Sep 17 '10 at 23:57 @Casey: Also, do note that for reduce problem I've post a compact stylesheet.

– user357812 Sep 18 '10 at 0:01 The first stylesheet you posted produces the result I'm looking for. The test case you created is way better than the one I presented, so thanks for that. Now I'm trying to get the result to render in FireFox 3.6 -- I need to remove the node but I'm struggling since I don't fully understand the selectors.

Any suggestions? – Casey Sep 20 '10 at 4:18 @Casey: I'm glad it helped you. When ussing an identity transformation pattern, in order to remove nodes you need to match the nodes an bypass, as example: – user357812 Sep 20 '10 at 12:36.

Well I developed this before I saw your comment that you're stuck with 1.0. But you said you're curious about 2.0, so here it is: Given the input: line 1 line 2 line 3 it yields the desired output: line 1 line 2 line 3 The only thing that requires XSLT 2.0 about this is the . You could do a similar thing by writing a template that recursively processes strings, looking for '\n' characters, using normalize-space, and surrounding the remaining pieces of text with .

Sorry about that -- thanks very much! Is there any chance that a 1.0 solution exists? – Casey Sep 17 '10 at 7:57 @Casey, see the last paragraph, which I just added.

I gotto go to bed or I'd think about writing it. Hopefully Dimitre or Alejandro will be along in a few hours. :-) – LarsH Sep 17 '10 at 8:01 Ok, thanks for your help.

I'll see if I can figure out that last paragraph. I'm still getting familiar with XSLT, so hopefully you come back when you wake up! :) – Casey Sep 17 '10 at 8:07.

A slight correction of your transformation: when applied on the provided XML document: line 1 line 2 line 3 produces the wanted result: line 1 line 2 line 3.

Thanks for this -- much appreciated. I'm going to go over it this weekend and weigh it against Alejandro's solution. It's great to see the different angles of attack; I've learned a lot – Casey Sep 17 '10 at 21:31 Although your solution produces the result I initially requested, unfortunately my test case was not sufficient.

With Alejandro's more complex example I've realized that his solution is better for my application. Thanks for your time though, seeing your solution helped greatly – Casey Sep 20 '10 at 4:16.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions