Subject: Re: [xsl] Tokenizing mixed content From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Fri, 17 May 2019 13:41:20 -0000 |
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:
Ive 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.
<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: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>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Tokenizing mixed content, Martin Honnen martin | Thread | Re: [xsl] Tokenizing mixed content, Edward Porter edward |
Re: [xsl] Tokenizing mixed content, Martin Honnen martin | Date | Re: [xsl] Multiple replace() in XSL, Dimitre Novatchev dn |
Month |