Re: [xsl] xsl:number query

Subject: Re: [xsl] xsl:number query
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 08 Mar 2010 16:55:39 -0500
At 2010-03-08 16:48 -0500, Terry Ofner wrote:
I am having trouble getting an accurate count using xsl:number.

Here is a snippet of my input document:

<div class="story">
<p class="test">A</p>
<p class="head-testname">READING COMPREHENSION</p>
<p class="bodytext-directionsrevise">Directions: Read the
selection. Then answer the questions that follow.</p>
<p class="head-selectiontitle">Jason and the Golden Fleece</p>
...
<p class="bodytext-directionsrule1">Directions: Read the
selection. Then answer the questions that follow.</p>
<p class="head-selectiontitle">Freight</p>
<p class="bodytext-selectionintro">This is an ... Underground
Railroad.</p>
<p class="bodytext-subhead">Cast of Characters</p>
</div>


I am attempting to include in the same sequence both <p
class="bodytext-directionsrevise"> and <p class="bodytext- directionsrule1">.

Here is the relevant template from my 2.0 stylesheet:

<xsl:template match="p[@class='bodytext-directionsrevise'] |
p[@class='bodytext-directionsrule1']">
<narrative>
     <xsl:attribute name="name"><xsl:number select="." count="*"
from="story"></xsl:number></xsl:attribute>

You are using count= incorrectly. It is a match pattern. You indicate those items that participate in the counting:


  count="p[@class='bodytext-directionsrevise'] |
         p[@class='bodytext-directionsrule1']"

... or if you are using XSLT 2:

count="p[@class=('bodytext-directionsrevise','bodytext-directionsrule1')]"

How can I tell xsl:number to count the specified attributes?

I'm assuming you mean "count the p elements that have the specified attributes".


BTW, it happens that my XSLT Video lecture on <xsl:number> is the exposed example lecture on YouTube:

http://www.youtube.com/watch?v=PrNjJCh7Ppg&amp;fmt=18

The entire video is 24 hours long. This lecture is about 25 minutes long. The video is sold with a copy of our PDF book (with perpetual updates), and a copy of the hands-on exercises that are walked through by me in the lectures. The overview of the entire video is here:

http://www.youtube.com/watch?v=VTiodiij6gE&amp;fmt=18

I hope this helps.

. . . . . . . . . . Ken

--
XSLT/XQuery training:      after http://XMLPrague.cz 2010-03-15/19
XSLT/XQuery training:         San Carlos, California 2010-04-26/30
Principles of XSLT for XQuery Writers: San Francisco,CA 2010-05-03
XSLT/XQuery training:                 Ottawa, Canada 2010-05-10/14
XSLT/XQuery/UBL/Code List training: Trondheim,Norway 2010-06-02/11
Vote for your XML training:   http://www.CraneSoftwrights.com/s/i/
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

Current Thread