|
Subject: Re: [xsl] Using xsl:iterate to get a count From: "Rolf Ade rolf@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Wed, 1 Jul 2026 22:45:45 -0000 |
If I understand the\xA0requirement I think you just want
<xsl:stylesheet version="3.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform <http://www.w3.org/1999/XSL/Transform>">
\xA0 <xsl:template match="chapter">
\xA0 \xA0 <xsl:text> Number of gaps =</xsl:text>
\xA0 \xA0 <xsl:value-of select="count(bookmark[
\xA0 \xA0 \xA0 preceding-sibling::bookmark
\xA0 \xA0 \xA0 and
\xA0 \xA0 \xA0 number(substring-after(@number,'-'))
\xA0 \xA0 \xA0 !=
(1+number(substring-after(preceding-sibling::bookmark[1]/@number,'-')))
\xA0 \xA0 \xA0 ])"/>
\xA0 </xsl:template>
</xsl:stylesheet>
which makes
\xA0 \xA0Number of gaps =3
David
On Wed, 1 Jul 2026 at 19:29, rick@xxxxxxxxxxxxxx <mailto:rick@xxxxxxxxxxxxxx> <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx <mailto:xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>> wrote:
Hi All,____
__ __
I am have a series of bookmark elements and I am trying to find the absolute number of gaps between the @number elements. In my example, there are 3 gaps: between 21-2 and 21-5; between 21-7 and 21-11; and between 21-11 and 21-15. ____
__ __
I set up a named template and am expecting an integer of 3, but instead I am getting 011. I am missing something fundamental. Any help would be appreciated. Thank you.____
__ __
Rick Quatro____
__ __
<?xml version="1.0" encoding="UTF-8"?>____
<map>____
\xA0 <chapter name="Chapter21TOC.fm" number="21" page="1523">____
\xA0\xA0\xA0 <title>Chapter 21 Common Procedural Language and Notice of Court Proceeding</title>____
\xA0\xA0\xA0 <bookmark name="Form21-1.fm" type="form" number="21-1" page="1525">____
\xA0\xA0\xA0\xA0\xA0 <title>Form 21-1 Notice of Hearing</title>____
\xA0\xA0\xA0 </bookmark>____
\xA0\xA0\xA0 <bookmark name="Form21-2.fm" type="form" number="21-2" page="1528">____
\xA0\xA0\xA0\xA0\xA0 <title>Form 21-2 Notice of Hearing</title>____
\xA0\xA0\xA0 </bookmark>____
\xA0\xA0\xA0 <bookmark name="Form21-5.fm" type="form" number="21-5" page="1531">____
\xA0\xA0\xA0\xA0\xA0 <title>Form 21-5 Objection to Notice of Hearing</title>____
\xA0\xA0\xA0 </bookmark>____
\xA0\xA0\xA0 <bookmark name="Form21-6.fm" type="form" number="21-6" page="1535">____
\xA0\xA0\xA0\xA0\xA0 <title>Form 21-6 Order on Objection to Notice of Hearing</title>____
\xA0\xA0\xA0 </bookmark>____
\xA0\xA0\xA0 <bookmark name="Form21-7.fm" type="form" number="21-7" page="1537">____
\xA0\xA0\xA0\xA0\xA0 <title>Form 21-7 Objection to Notice of Trial</title>____
\xA0\xA0\xA0 </bookmark>____
\xA0\xA0\xA0 <bookmark name="Form21-11.fm" type="form" number="21-11" page="1541">____
\xA0\xA0\xA0\xA0\xA0 <title>Form 21-11 Certificate of Service</title>____
\xA0\xA0\xA0 </bookmark>____
\xA0\xA0\xA0 <bookmark name="Form21-15.fm" type="form" number="21-15" page="1542">____
\xA0\xA0\xA0\xA0\xA0 <title>Form 21-15 Suggested Language for Appearances before the Court</title>____
\xA0\xA0\xA0 </bookmark>____
\xA0 </chapter>____
</map>____
__ __
<?xml version="1.0" encoding="UTF-8"?>____
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform <http://www.w3.org/1999/XSL/Transform>"____
\xA0\xA0\xA0 xmlns:xs="http://www.w3.org/2001/XMLSchema <http://www.w3.org/2001/XMLSchema>"____
\xA0\xA0\xA0 exclude-result-prefixes="xs"____
\xA0\xA0\xA0 version="3.0"____
\xA0\xA0\xA0 expand-text="yes">____
____
\xA0\xA0\xA0<xsl:output method="text" indent="no"/>____
____
\xA0\xA0\xA0\xA0<xsl:template match="/map">____
\xA0\xA0\xA0\xA0\xA0\xA0\xA0 <xsl:apply-templates/>____
\xA0\xA0\xA0 </xsl:template>____
__ __
\xA0\xA0\xA0 <xsl:template match="chapter">____
\xA0\xA0\xA0\xA0\xA0\xA0\xA0 <xsl:variable name="reserved-count">____
\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0 <xsl:choose>____
\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0 <xsl:when test="exists(bookmark[@type='form'])">____
\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0 <xsl:call-template name="get-reserved-count"/>____
\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0 </xsl:when>____
\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0 <xsl:otherwise>0</xsl:otherwise>____
\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0 </xsl:choose>____
\xA0\xA0\xA0\xA0\xA0\xA0\xA0 </xsl:variable>____
\xA0\xA0\xA0\xA0\xA0\xA0\xA0 <xsl:text>{@name} {$reserved-count}</xsl:text>____
\xA0\xA0\xA0 </xsl:template>____
____
\xA0\xA0\xA0\xA0<xsl:template name="get-reserved-count">____
\xA0\xA0\xA0\xA0\xA0\xA0\xA0 <xsl:sequence><xsl:iterate select="bookmark[@type = 'form']">____
\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0 <xsl:param name="reserved-count" select="0" as="xs:integer"/>____
\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0 <xsl:if test="preceding-sibling::bookmark[1][@type = 'form']">____
\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0 <xsl:variable name="prev-form-num" select="tokenize(preceding-sibling::bookmark[1]/@number,'\-')"/>____
\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0 <xsl:variable name="curr-form-num" select="tokenize(@number,'\-')"/>____
\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0 <xsl:variable name="gap" select="(number($curr-form-num[2]) - number($prev-form-num[2]))"/>____
\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0 <xsl:choose>____
\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0 <xsl:when test="$gap > 1">____
\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0 <xsl:next-iteration>____
\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0 <xsl:with-param name="reserved-count" select="$reserved-count + 1" as="xs:integer"/>____
\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0 </xsl:next-iteration>____
\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0 </xsl:when>____
\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0 <xsl:when test=".[last()]">{$reserved-count}</xsl:when>____
\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0 <xsl:otherwise>____
\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0 <xsl:next-iteration>____
\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0 <xsl:with-param name="reserved-count" select="$reserved-count" as="xs:integer"/>____
\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0 </xsl:next-iteration>____
\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0 </xsl:otherwise>____
\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0 </xsl:choose>____
\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0 </xsl:if> ____
\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0</xsl:iterate></xsl:sequence>____
\xA0\xA0\xA0 </xsl:template>____
____
\xA0\xA0\xA0\xA0<xsl:mode on-no-match="shallow-skip"/>____
____
</xsl:stylesheet>____
XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list> EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/2739265> (by email)
XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/652039> (by email <>)
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] Using xsl:iterate to get , rick@xxxxxxxxxxxxxx | Thread | |
| Re: [xsl] Using xsl:iterate to get , rick@xxxxxxxxxxxxxx | Date | |
| Month |