Re: [xsl] Empty input in analyze-string

Subject: Re: [xsl] Empty input in analyze-string
From: "Mathieu Malaterre" <mathieu.malaterre@xxxxxxxxx>
Date: Fri, 4 Jul 2008 16:11:22 +0200
On Fri, Jul 4, 2008 at 3:42 PM, Michael Kay <mike@xxxxxxxxxxxx> wrote:
>> if para2 is an empty element, then the regex success and
>> return an empty string. How do I express in my regex that
>> empty is a non-matching regex ?
> Further to Joe's response: analyze-string partitions the input string into a
> sequence of substrings, passing substrings that match the regex to
> xsl:matching-substring and those that don't match to
> xsl:non-matching-substring. If the input is empty, there will be no
> substrings, therefore no calls on either xsl:matching-substring or
> xsl:non-matching-substring.
> If you want to test whether the string as a whole matches the regex, use the
> matches() function.

Ok I think I am getting closer now. My goal is simply to recursively
iterate over preceeding <para> element in search for a matching regex.
I must have made a mistake with the recusion calls...

<para>C.1. section</para>
<para>C.1.1 section</para>
<para>C.1.1.1 section</para> <!-- correct solution -->

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl=""; version="2.0">
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
  <xsl:variable name="myregex">^([CF]\.[0-9\.]+)\s*(.*)$</xsl:variable>
  <xsl:template name="get-section-reference">
    <xsl:param name="article"/>
    <xsl:param name="n"/>
    <xsl:variable name="para" select="article/preceding::para[$n]"/>
      <xsl:when test="matches($para, $myregex)">
        <xsl:analyze-string select="." regex="{$myregex}">
              <xsl:value-of select="."/>
<!-- no need to non matching-substring case -->
        <xsl:call-template name="get-section-reference">
          <xsl:with-param name="article" select="."/>
          <xsl:with-param name="n" select="$n+1"/>
  <xsl:template match="/">
      <xsl:for-each select="//table">
        <xsl:call-template name="get-section-reference">
          <xsl:with-param name="article" select="."/>
          <xsl:with-param name="n" select="1"/>


Current Thread