xsl-list
[Top] [All Lists]

Re: [xsl] Seeking a smarter tokenize for augmented text

2021-05-06 04:25:22
I would have a two-step 

transform the new-line into an empty element <newline/> in a first pass 
(identity transform with an analyze-string in the text nodes) 
and do a for-each-group on all nodes, starting on the newline element in the 
second pass 

you could do the in a single step, for each group on all non text nodes + all 
text nodes, but split (when they have a newline in them) 

Met vriendelijke groeten, 
Best regards, 

Geert Bormans 

----- Op 6 mei 2021 om 11:16 schreef Trevor Nicholls 
trevor(_at_)castingthevoid(_dot_)com 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com>: 



Hi 



Turning xml like this: 



<textlines>this is line 1 

this is line 2 

this is line 3</textlines> 



into something like this: 



<textlines> 

<line>this is line 1</line> 

<line>this is line 2</line> 

<line>this is line 3</line> 

</textlines> 



is simple and I have functions that do it. But they rely on <textlines> being 
an xs:string, which is processed by a trivial function I wrote: 



<xsl:function name="my:intoLines" as="xs:string*"> 

<xsl:param name="arg" as="xs:string?" /> 

<xsl:sequence select="tokenize( $arg, '(\r\n?|\n\r?)' )" /> 

</xsl:function> 



I would like to extend this so that it can handle an element consisting of text 
lines with some embedded markup (there won't be much, but there will be some). 
For example, taking: 



<textlines>this is line <seq>1</seq> 

this is <var>line</var> 2 

this <emph>is</emph> line 3</textlines> 



and producing 



<textlines> 

<line>this is line <seq>1</seq></line> 

<line>this is <var>line</var> 2</line> 

<line>this <emph>is</emph> line 3</line> 

</textlines> 



Sequence and tokenize isn't adequate but is there a way to do this that won't 
overtax my brain too much? 



cheers 

T 
[ http://www.mulberrytech.com/xsl/xsl-list | 
XSL-List info and archive ] 
[ http://lists.mulberrytech.com/unsub/xsl-list/554170 | EasyUnsubscribe ] ( [  
| by email ] ) 
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--
<Prev in Thread] Current Thread [Next in Thread>