RE: [xsl] Having problem matching ranges

Subject: RE: [xsl] Having problem matching ranges
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 20 Jul 2006 14:17:17 +0100
Since you're using XSLT 2.0, try declaring the types of your variables, for
example

<xsl:variable name="id" select="@id" as="xs:integer"/>

That will make this kind of problem vastly easier to diagnose.

We would also be more likely to read your code if it was properly indented.
(Try checking your mailer to ensure you are sending the mail as plain text,
not HTML).

Michael Kay
http://www.saxonica.com/
 

> -----Original Message-----
> From: Jeff Sese [mailto:jsese@xxxxxxxxxxxx] 
> Sent: 20 July 2006 13:06
> To: Xsl-List
> Subject: [xsl] Having problem matching ranges
> 
> 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][nu
> mber(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][nu
> mber(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