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

Re: analyze-string question

Subject: Re: analyze-string question
From: "Imsieke, Gerrit, le-tex" <gerrit.imsieke@xxxxxxxxx>
Date: Sat, 27 Oct 2012 15:28:23 +0200
Re:  analyze-string question
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 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).

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


-- 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

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.