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

Re: Selecting 400 characters before a string such as Y

Subject: Re: Selecting 400 characters before a string such as YYY in a large document.
From: Wolfgang Laun <wolfgang.laun@xxxxxxxxx>
Date: Sun, 13 Jun 2010 11:57:24 +0200
Re:  Selecting 400 characters before a string such as Y
I don't see the necessity for reversing the content. True, "greedy" matching
(implying backup) may not be the fastest way in some situations; as an
alternative there is "reluctant" matching (e.g. '.*?').

But if the YYY is a literal string (not a pattern) substring-before is

    <xsl:variable name="bef" select="substring-before(.,'YYY')"/>
    <xsl:value-of select="substring($bef,string-length($bef)-400+1,400)"/>

If there's the possibility that there aren't 400 characters before YYY,
add a choice.

Here is the solution with pattern matching:
    <xsl:variable name="bef" select="."/>
    <xsl:value-of select="replace($bef,'^.*?(.{400})YYY.*$', '$1')"/>
Here, using '.{1,400}' would be necessary to handle "short" cases.


On 13 June 2010 10:11, Alex Muir <alex.g.muir@xxxxxxxxx> wrote:
> Hi,
> I need to select 400 characters before a string such as YYY in a
> larger text document.
> I've in the past reversed the content to then find the 400 characters
> before YYY using regex effectively however I'm wondering if there is a
> better perhaps simpler way to do this in xslt?
> Thanks
> --
> Alex
> An informal recording with one mic under a tree leads to some pretty
> sweet acoustic sounds.
> https://sites.google.com/site/greigconteh/albums/diabarte-and-sons

Current Thread


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.
First Name
Last Name
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.