xsl-list
[Top] [All Lists]

Re: [xsl] analyze-string question

2012-10-27 08:28:48
David,

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 what’s 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).

Gerrit


<?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:copy>
      <xsl:sequence select="my:wrap-nested(., '&lt;([^aeiou].+)&gt;')"/>
    </xsl:copy>
  </xsl:template>

  <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:matching-substring>
        <alt>
          <xsl:sequence select="my:wrap-nested(regex-group(1), $regex)"/>
        </alt>
      </xsl:matching-substring>
      <xsl:non-matching-substring>
        <xsl:sequence select="my:stress(.)"/>
      </xsl:non-matching-substring>
    </xsl:analyze-string>
  </xsl:function>

  <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:matching-substring>
        <stress>
          <xsl:value-of select="regex-group(1)"/>
        </stress>
      </xsl:matching-substring>
      <xsl:non-matching-substring>
        <xsl:value-of select="."/>
      </xsl:non-matching-substring>
    </xsl:analyze-string>
  </xsl:function>

</xsl:stylesheet>



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.

Best,

David

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


--
Gerrit Imsieke
Geschäftsfü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(_dot_)imsieke(_at_)le-tex(_dot_)de, http://www.le-tex.de

Registergericht / Commercial Register: Amtsgericht Leipzig
Registernummer / Registration Number: HRB 24930

Geschäftsführer: Gerrit Imsieke, Svea Jelonek,
Thomas Schmidt, Dr. Reinhard Vöckler

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>