Subject: Re: [xsl] 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 |
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
<- Previous | Index | Next -> |
---|---|---|
[xsl] Selecting 400 characters befo, Alex Muir | Thread | Re: [xsl] Selecting 400 characters , Alex Muir |
Re: [xsl] distinguish whether varia, Martin Honnen | Date | Re: [xsl] Selecting 400 characters , Alex Muir |
Month |