[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] analyze-string question

Subject: Re: [xsl] analyze-string question
From: "Imsieke, Gerrit, le-tex" <gerrit.imsieke@xxxxxxxxx>
Date: Sat, 27 Oct 2012 15:28:23 +0200


When I revisited the solution that I proposed, I noticed some redundancy (xsl:choose) in the function my:wrap-nested. Please find the reworked solution below.

Th solution succeeds at nesting the alts by virtue of the greediness of the '.+' regex. If there is no prior markup in an alt group (no <stress>, in particular), it will select the outermost bracket pair and then process whats between the brackets recursively.

But it cannot, unfortunately, mitigate the risk of ambiguous input (when alt forms are allowed to start with vowels and when there are no other rules to unequivocally discern stressing markup from alt markup).


<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:my="my" version="2.0" exclude-result-prefixes="my xs" >

  <xsl:template match="p">
      <xsl:sequence select="my:wrap-nested(., '&lt;([^aeiou].+)&gt;')"/>

  <xsl:function name="my:wrap-nested" as="node()*">
    <xsl:param name="string" as="xs:string" />
    <xsl:param name="regex" as="xs:string" />
    <xsl:analyze-string select="$string" regex="{$regex}" flags="i">
          <xsl:sequence select="my:wrap-nested(regex-group(1), $regex)"/>
        <xsl:sequence select="my:stress(.)"/>

  <xsl:function name="my:stress" as="node()*">
    <xsl:param name="string" as="xs:string" />
    <xsl:analyze-string select="$string" regex="&lt;([aeiou])" flags="i">
          <xsl:value-of select="regex-group(1)"/>
        <xsl:value-of select="."/>


On 2012-10-27 14:45, Birnbaum, David J wrote:
Dear XSLT List,

Thanks very much to Michael and Gerrit for their quick and helpful responses, which do, indeed, point to an effective solution.



-- Gerrit Imsieke Geschdftsf|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

Geschdftsf|hrer: Gerrit Imsieke, Svea Jelonek,
Thomas Schmidt, Dr. Reinhard Vvckler

Current Thread