[xsl] testing for numbers of nodes

Subject: [xsl] testing for numbers of nodes
From: Charles Muller <cmuller-lst@xxxxxxxxxxxxxxx>
Date: Sat, 10 May 2008 19:59:03 +0900
Dear Friends,

I'm trying my hand at XSLT for the first time in few years, trying to get a dictionary ready for print-out. I've got just about everything working, but I'm having trouble with one point. In the explanatory section of each entry, I have this structure:

<headword>The Term</headword>
<sense_area>
<sense>Explanation of meaning #1</sense>
<sense>Explanation of meaning #2</sense>
<sense>Explanation of meaning #3</sense>
</sense_area>

I want this to be in inline paragraph format, not list format, so I have used <xsl:number>, so that I can output something like this:

The Term: (I) Explanation of meaning 1. (II) Explanation of meaning 2. (III) Explanation of meaning 3.

I did this with:

      <xsl:for-each select="sense_area"><xsl:text> </xsl:text>
       <xsl:for-each select="sense">
       (<xsl:number format="I"/>)<xsl:apply-templates />
       </xsl:for-each>
      </xsl:for-each>

I'm OK up to here with the XSL, but the only problem is, if there is only one <sense> I don't want any numbers at all. So I assume that I need to do a test, which will turn off numbering if the amount of <sense> is not greater than one. So I've tried a few things using count(), without success. I've been playing with this for a while now, and can't make anything work. The present code I've got (not working) is:

<xsl:for-each select="sense_area"><xsl:text> </xsl:text>
<xsl:for-each select="sense">
<xsl:if test="count(sense) &gt; I">(<xsl:number format="I"/>)</xsl:if> <xsl:apply-templates />
</xsl:for-each>
</xsl:for-each>


Can someone perhaps see what is wrong with this?

Thank you very much.

Chuck
--

---------------------------
Charles Muller

Toyo Gakuen University
Faculty of Humanities
1660 Hiregasaki, Nagareyama-shi
Chiba 270-0161 JAPAN
Mobile Phone: 090-9310-1787

Web Site: Resources for East Asian Language and Thought
http://www.acmuller.net

<acmuller[at]jj.em-net.ne.jp>

Current Thread