[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] struggling with

Subject: RE: [xsl] struggling with <xsl:analyze-string>
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 26 Jan 2005 23:08:03 -0000

> In my deepest hour of sorrows I write to you once more...

May all your sorrows be as unimportant as this one.

> I just took a closer look to the <xsl:analyze-string> instruction.
> XML fragment (I have no control of the structure as you can see ;)):
> <par class="45_UeberschrPara" xml:lang="en"
> style="word-break-inside: hyphenate; color: #000000;
> ">In-Kraft-Treten</par>
> <par class="51_Abs" xml:lang="en" style="word-break-inside:
> hyphenate; ">
> 	<inline class="991_GldSymbol">' 2.</inline>
> 	<inline style="color: #000000;">
> 	<inline style="font-weight: bold;"> </inline>Diese
> Verordnung tritt mit 4. Jdnner 2005 in Kraft.</inline>
> </par>
> <par class="68_UnterschrL" xml:lang="en"
> style="word-break-inside: hyphenate; color: #000000; ">Pribil
> Traum|ller</par>
> What I need to do:
> I need to search in all nodes after
> par[@class='45_UeberschrPara'] for a date in the Format
> "[DD]. [Mn] [YYYY]" and pass this date to a named template.
> So far so good.
> I thought that <xsl:analyze-string> would be the thing to
> use,

This does look like something where matches() would do the job. The
particular situation where xsl:analyze-string is useful is where you need to
split the matching string into parts, based on the way it matches the
regular expression. If you only need to test whether or not there is a
match, then the matches function in XPath is usually a simpler solution.

 so I tried:
> <!-- I used <xsl:for-each> because <xsl:analyze-string>
> doesn't allow a sequence with more than one item -->
> <xsl:for-each
> select="part/section//*[preceding::par[@class='45_UeberschrPar
> a' and contains(., 'In-Kraft-Treten')]]">
> 	<!-- Until here everything works fine -->
> 	<xsl:analyze-string select="." regex="\d{4}">
> 		<!-- No output *sigh*. -->

If you're getting no output from analyze-string then a useful debugging
technique is to add an <xsl:non-matching-substring> child instruction that
calls <xsl:message> to output the non-matching string. (In this case, as DC
pointed out, the culprit is the braces in the regex: a common pitfall.)

Michael Kay

Current Thread