Re: [xsl] Selecting 400 characters before a string such as YYY in a large document.

Subject: Re: [xsl] Selecting 400 characters before a string such as YYY in a large document.
From: Alex Muir <alex.g.muir@xxxxxxxxx>
Date: Sun, 13 Jun 2010 10:10:52 +0000
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

Current Thread