[xsl] Having problem matching ranges

Subject: [xsl] Having problem matching ranges
From: Jeff Sese <jsese@xxxxxxxxxxxx>
Date: Thu, 20 Jul 2006 20:05:39 +0800
hi! One more question before i sleep. I have this xsl:

<xsl:key name="commentary" match="node()[name()!='T_F_entry']" use="generate-id(preceding-sibling::T_F_entry[1])"/>

<xsl:template match="T_F_entry">
<xsl:variable name="id" select="@id"/>
<xsl:variable name="type" select="@type"/>
<xsl:variable name="n" select="@n"/>
<xsl:choose>
<xsl:when test="@n[matches(.,'-')]">
<xsl:variable name="min" as="xs:integer">
<xsl:value-of select="number(substring-before(@n,'-'))"/>
</xsl:variable>
<xsl:variable name="max" as="xs:integer">
<xsl:value-of select="number(substring-after(@n,'-'))"/>
</xsl:variable>
<xsl:for-each select="$min to $max">
<xsl:variable name="ctr" as="xs:integer" select="."/>
<xsl:if test="exists(document($commentary.file)//T_F_entry[@id=$id and @type=$type and (@n[matches(.,'-') and number(substring-before(.,'-'))&lt;=$ctr and number(substring-after(.,'-'))>=$ctr] or @n=$ctr)])">
<xsl:call-template name="insert.comments">
<xsl:with-param name="idnum" select="$idnum"/>
<xsl:with-param name="id" select="$id"/>
<xsl:with-param name="type" select="$type"/>
<xsl:with-param name="n" select="$ctr"/>
</xsl:call-template>
</xsl:if>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:if test="exists(document($commentary.file)//T_F_entry[@id=$id and @type=$type and (@n[matches(.,'-')][number(substring-before(.,'-'))&lt;=$n][number(substring-after(.,'-'))>=$n] or @n=$n)])">
<xsl:call-template name="insert.comments">
<xsl:with-param name="idnum" select="$idnum"/>
<xsl:with-param name="id" select="$id"/>
<xsl:with-param name="type" select="$type"/>
<xsl:with-param name="n" select="$n"/>
</xsl:call-template>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:template>


<xsl:template name="insert.comments">
<xsl:param name="idnum"/>
<xsl:param name="id"/>
<xsl:param name="type"/>
<xsl:param name="n"/>
<xsl:element name="div">
<xsl:apply-templates select="document($commentary.file)//T_F_entry[@id=$id and @type=$type and (@n[matches(.,'-')][number(substring-before(.,'-'))&lt;=$n][number(substring-after(.,'-'))>=$n] or @n=$n)]/key('commentary',generate-id())" mode="commentary"/>
</xsl:element>
</xsl:template>


main source:

<root>
<T_F_entry id="270" type="F" n="5">
some text
</T_F_entry>
<T_F_entry id="270" type="F" n="5-6">
some text
</T_F_entry>
</root>

commentary.file:

<T_F_entry id="270" type="F" n="5-6"/> some text 5-6 <T_F_entry id="270" type="F" n="5"/> some text 5 <T_F_entry id="270" type="F" n="6"/> some text 6 <T_F_entry id="270" type="F" n="7"/> some text 7

needed ouput:

<div>some text 5-6 some text 5</div>
<div>some text 5-6 some text 5 some text 6</div>

When i run the xslt i receive a cannot convert string "5-6" to a double error.
Thanks,
Jeff


Current Thread