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

Re: Tokenizing mixed content

Subject: Re: Tokenizing mixed content
From: "Edward Porter edward.porter@xxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 20 May 2019 13:24:04 -0000
Re:  Tokenizing mixed content
Thanks, Martin. This is exactly what I needed to get started. I think I can
massage the punctuation after replacing the pipes for choice elements.

-----Original Message-----
From: Martin Honnen martin.honnen@xxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Friday, May 17, 2019 9:41 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  Tokenizing mixed content

EXTERNAL

On 17.05.2019 15:29, Martin Honnen martin.honnen@xxxxxx wrote:
> On 17.05.2019 15:22, Edward Porter edward.porter@xxxxxxx wrote:
>> I am working on a conversion script transforming from a prior DTD to
>> a new DTD, and as part of this transformation, we are hoping to parse
>> some mixed content into separate nested elements. The content is "|"
>> delimited, but I am having a tough time coming up with a way to group
>> the text and sibling elements. What follows are some permutations of
>> input and expected output:

>> I've got access to XSL 2, and possibly XSL3 if necessary.
>
>
> A two pass transformation that first processes text nodes to "convert"
> the pipe character into an element (e.g. <pipe/>) and then in second
> step uses for-each-group group-ending-with="pipe" should help.

Along the lines of

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

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

   <xsl:mode name="pipe-char-to-pipe-el" on-no-match="shallow-copy"/>

   <xsl:mode name="analyze-string"/>

   <xsl:template match="text()" mode="pipe-char-to-pipe-el">
       <xsl:apply-templates select="analyze-string(., '\s*\|\s*')"
mode="analyze-string"/>
   </xsl:template>

   <xsl:template match="fn:match" mode="analyze-string">
       <pipe/>
   </xsl:template>

   <xsl:variable name="first-pass-result">
       <xsl:apply-templates mode="pipe-char-to-pipe-el"/>
   </xsl:variable>

   <xsl:template match="/">
       <xsl:apply-templates select="$first-pass-result/node()"/>
   </xsl:template>

   <xsl:template match="argument">
       <xsl:copy>
           <xsl:for-each-group select="node()" group-ending-with="pipe">
               <choice>
                   <xsl:apply-templates select="current-group()"/>
               </choice>
           </xsl:for-each-group>
       </xsl:copy>
   </xsl:template>

   <xsl:template match="pipe"/>

</xsl:stylesheet>

https://xsltfiddle.liberty-development.net/gWvjQfJ

Not sure when/where the quotes in the first example need to be eliminated.

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.