[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
Hi, As I understand it .*? or * would not restrict the number of identified characters to 400 and thus I was using .{1,400}YYY which causes a lot of backtracking My bad though perhaps due to fatigue I was not seeing in the drop down oxygen documentation that substring that accepted doubles.. odd i missed that.. substring($sourceString as xs:string?, $startingLoc as xs:double, $length as xs:double) Thanks Much On Sun, Jun 13, 2010 at 9:57 AM, Wolfgang Laun <wolfgang.laun@xxxxxxxxx> wrote: > 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 > suffcient. > > <out1> > <xsl:variable name="bef" select="substring-before(.,'YYY')"/> > <xsl:value-of select="substring($bef,string-length($bef)-400+1,400)"/> > </out1> > > If there's the possibility that there aren't 400 characters before YYY, > add a choice. > > Here is the solution with pattern matching: > <out2> > <xsl:variable name="bef" select="."/> > <xsl:value-of select="replace($bef,'^.*?(.{400})YYY.*$', '$1')"/> > </out2> > Here, using '.{1,400}' would be necessary to handle "short" cases. > > -W > > > > 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 > > -- 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|