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

Re: Seeking a smarter tokenize for augmented text

Subject: Re: Seeking a smarter tokenize for augmented text
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 7 May 2021 10:11:53 -0000
Re:  Seeking a smarter tokenize for augmented text
Am 06.05.2021 um 11:09 schrieb Trevor Nicholls trevor@xxxxxxxxxxxxxxxxxx:
>
> 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>
>

That part could be done with


<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:xs="http://www.w3.org/2001/XMLSchema"
     exclude-result-prefixes="#all"
     version="3.0">

   <xsl:mode on-no-match="shallow-copy"/>

   <xsl:mode name="insert-markers" on-no-match="shallow-copy"/>

   <xsl:template match="textlines">
       <xsl:copy>
           <xsl:variable name="transformed-textlines">
               <xsl:apply-templates mode="insert-markers"/>
           </xsl:variable>
           <xsl:for-each-group select="$transformed-textlines/node()"
group-ending-with="lb">
               <line>
                   <xsl:apply-templates select="current-group()"/>
               </line>
           </xsl:for-each-group>
       </xsl:copy>
   </xsl:template>

   <xsl:template mode="insert-markers" match="text()">
       <xsl:analyze-string select="." regex="\n+">
           <xsl:matching-substring>
               <lb/>
           </xsl:matching-substring>
           <xsl:non-matching-substring>
               <xsl:value-of select="."/>
           </xsl:non-matching-substring>
       </xsl:analyze-string>
   </xsl:template>

   <xsl:template match="lb"/>

</xsl:stylesheet>


https://xsltfiddle.liberty-development.net/6qaHaQK

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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.
Email
First Name
Last Name
Company
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.