[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Split element with mixed content

Subject: Re: Split element with mixed content
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Thu, 02 Aug 2007 19:01:48 +0200
Re:  Split element with mixed content
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

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).

-- Abel Braaksma

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.