[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Apparently MK and I were a bit on the same track, applying his notes to what I came up in my prev posts, see below, it may help you understand my solution, and, likely, optimize it:
Michael Kay wrote:
I assumed a matching for text, done with contains(., 'yourtexthere')
I assumed HTML where the P element cannot be a child of itself, and used ancestor::p to have a starting point.
I didn't do this, I used instead two modes to differentiate between 'before' and 'after'. My solution is probably more resource intensive.
In addition, in the midst of it all, you have the split of the text itself. I did it by using a predicate for testing if it is the right string and then use either the before or after bit.
Indeed. In my case: the text node and node comparison against that node.
I assumed the marker to be text()[contains(., 'yourstring')]
ah, didn't think of that. If you need that, you'll have to modify my code a bit.
After you have something, I reckon it is best to put it into some function, it will be worthwile if you can simply use it with copy-of or something and you can more easily reuse functions then templates (imho).
Re: [xsl] Split element with mixed content
Subject: Re: [xsl] Split element with mixed content From: Abel Braaksma <abel.online@xxxxxxxxx> Date: Thu, 02 Aug 2007 19:01:48 +0200 |
Apparently MK and I were a bit on the same track, applying his notes to what I came up in my prev posts, see below, it may help you understand my solution, and, likely, optimize it:
Michael Kay wrote:
0: for simplicity, assume an empty element <split/> at the split point.
I assumed a matching for text, done with contains(., 'yourtexthere')
1: generate the first element, by copying any node that precedes <split/> or
that is an ancestor of <split/>. (Easier in 2.0 with the << operator)
I assumed HTML where the P element cannot be a child of itself, and used ancestor::p to have a starting point.
2. generate the second element, by copying any node that follows <split/> or
that is an ancestor of <split/>. (So the nodes that are ancestors of
<split/> are copied into both halves.)
I didn't do this, I used instead two modes to differentiate between 'before' and 'after'. My solution is probably more resource intensive.
In addition, in the midst of it all, you have the split of the text itself. I did it by using a predicate for testing if it is the right string and then use either the before or after bit.
"Copy" here is in the sense of doing an <xsl:copy> and a recursive
apply-templates. The copy operations can be done by a suitably modified
identity template that takes the <split/> element as a parameter.
Indeed. In my case: the text node and node comparison against that node.
Without an explicit marker at the split point, it becomes a little more
difficult - I'm not sure how you want to identify where the split is to
occur.
I assumed the marker to be text()[contains(., 'yourstring')]
If there are multiple split points, do the above to split into two, then
apply the process recursively to the second half.
ah, didn't think of that. If you need that, you'll have to modify my code a bit.
After you have something, I reckon it is best to put it into some function, it will be worthwile if you can simply use it with copy-of or something and you can more easily reuse functions then templates (imho).
Cheers, -- Abel Braaksma
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Split element with mixed , Kevin Bird | Thread | RE: [xsl] Split element with mixed , Kevin Bird |
Re: [xsl] RE: Troubling passing par, Florent Georges | Date | Re: [xsl] RE: Troubling passing par, Martin Honnen |
Month |