Subject: Re: [xsl] XSLT Regex for Matching Curly Braces From: "Imsieke, Gerrit, le-tex gerrit.imsieke@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Mon, 10 Jun 2019 16:56:29 -0000 |
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0">
<xsl:template match="input"> <xsl:copy> <xsl:analyze-string select="." regex="{$regex}"> <xsl:matching-substring> <ph> <xsl:value-of select="regex-group(1)"/> </ph> </xsl:matching-substring> <xsl:non-matching-substring> <xsl:value-of select="."/> </xsl:non-matching-substring> </xsl:analyze-string> </xsl:copy> </xsl:template>
On 10.06.2019 18:30, Don Smith dsmith_lockesmith@xxxxxxxxx wrote:Hello,
I'm attempting to write a regex inB XSLT on matching curly braces and then produce the correct markup output. Between my lack of expertise in regex generally and the special circumstances in XSLT with regard to AVTs and curly braces I'm having little success.
The requirement is pretty straight-forward. Given a text node such as this:
} dui {elementum}. Potenti ullamcorper vitae tempus condimentum dignissim facilisis arcu ligula {elementum} { **//___^ I want the output markup to be:
} dui<ph>elementum</ph>. Potenti ullamcorper vitae tempus condimentum dignissim facilisis arcu ligula<ph>elementum</ph>{ **//___^ So, two parts to my question:
1. What is the correct regex in XSLT to match a set of curly braces with one or characters between them and no white space?
It all depends on where you put it.
2. Is <xsl:analyze-string> the best choice for processing the string via the regex and handling the output or is another approach preferred?
In XSLT 3 I think it is a bit easier using the analyze-string function and pushing the result through templates e.g. do
<xsl:apply-templates select="analyze-string(., '\{(\p{L}+)\}')" mode="wrap"/>
for your text node and then
B <xsl:template match="match" xpath-default-namespace="http://www.w3.org/2005/xpath-functions" mode="wrap"> B B B B B <ph> B B B B B B B B B <xsl:value-of select="group"/> B B B B B </ph> B </xsl:template>
to handle the processing.
-- Gerrit Imsieke GeschC$ftsfC<hrer / Managing Director le-tex publishing services GmbH Weissenfelser Str. 84, 04229 Leipzig, Germany Phone +49 341 355356 110, Fax +49 341 355356 510 gerrit.imsieke@xxxxxxxxx, http://www.le-tex.de
Registergericht / Commercial Register: Amtsgericht Leipzig Registernummer / Registration Number: HRB 24930
GeschC$ftsfC<hrer / Managing Directors: Gerrit Imsieke, Svea Jelonek, Thomas Schmidt
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] XSLT Regex for Matching C, Martin Honnen martin | Thread | Re: [xsl] XSLT Regex for Matching C, Michael Kay mike@xxx |
Re: [xsl] XSLT Regex for Matching C, Martin Honnen martin | Date | Re: [xsl] XSLT Regex for Matching C, Michael Kay mike@xxx |
Month |