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

Subject: Re: [xsl] Seeking a smarter tokenize for augmented text
From: "Imsieke, Gerrit, le-tex gerrit.imsieke@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 6 May 2021 09:13:51 -0000
Hi Trevor,

If the markup in the lines doesn't stretch across line breaks, you can insert empty elements for each line break using xsl:analyze-string in a first pass.

In the second pass, you then group the nodes below textlines, starting or ending with such an empty linebreak element that you introduced in the first pass.


On 06.05.2021 11:09, Trevor Nicholls trevor@xxxxxxxxxxxxxxxxxx wrote:

Turning xml like this:

<textlines>this is line 1

this is line 2

this is line 3</textlines>

into something like this:


<line>this is line 1</line>

<line>this is line 2</line>

<line>this is line 3</line>


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*">

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

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


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


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

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

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


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



Current Thread