I am creating a specialized table of contents that will contain page ranges
(pp. 5-12, p. 17). I am starting with a flat structure in which the page
reference for each entry has been changed to a @startNum attribute:
<Book>
<UnitName startNum="2">Unit Name</UnitName>
<chapter startNum="4" number="1">
<title>Chapter 1: ...</title>
</chapter>
<lesson startNum="5">...</lesson>
<sublesson startNum="5">1. ...</sublesson>
<sublesson startNum="7">2. ...</sublesson>
<sublesson startNum="8">3. ...</sublesson>
<sublesson startNum="12">4. ...</sublesson>
<lesson startNum="13">...</lesson>
<sublesson startNum="13">1. ...</sublesson>
<italicFeature singlePage="17">...</italicFeature>
<sublesson startNum="18">2. ...</sublesson>
<sublesson startNum="21">3. ...</sublesson>
<sublesson startNum="22">4. ...</sublesson>
<lesson startNum="24">...</lesson>
<italicFeature singlePage="26">...</italicFeature>
<sublesson startNum="29">5. ...</sublesson>
<lesson startNum="33">...</lesson>
<chapter startNum="34" number="2">
<title>Chapter 2: ...</title>
</chapter>
<!--much more like this-->
</Book>
The desired output would add an endNum attribute to each element:
<chapter startNum="4" number="1" endNum="33">
<title>Chapter 1: ...</title>
</chapter>
<lesson startNum="5" endNum="12">...</lesson>
Issues:
Each <italicFeature> element is single page entry that must be included in the
sublesson page range.
<sublesson startNum="13" endNum="17">1. ...</sublesson>
<italicFeature singlePage="17">...</italicFeature>
<sublesson startNum="18">2. ...</sublesson>
My current strategy for generating the endNum attributes is to subtract 1 from
the following startNum if it satisfies certain conditions. In this template, I
first test to see if the following @startNum is equal to the current @startNum.
If it is, then the @endNum will be the same as the @startNum. If it isn't, then
I need to subtract 1 from the following @startNum.
<xsl:template match="sublesson">
<xsl:choose>
<xsl:when test="following::*/@startNum[1] = @substartNum">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:attribute name="endNum">
<xsl:value-of select="@startNum"/>
</xsl:attribute>
<xsl:apply-templates/>
</xsl:copy>
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:attribute name="endNum">
<xsl:value-of select="following::*[1]/@startNum -1"/>
<!--offending line-->
</xsl:attribute>
<xsl:apply-templates/>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
All well and good except that the offending line noted above does not seem to
select the first following @startNum. Here is a snippet of my output:
<lesson startNum="13" endNum="23"/>...</lesson>
<sublesson startNum="13" endNum="">1. ...</sublesson> <!--no
endNum-->
<italicFeature singlePage="17">C...</italicFeature>
<sublesson startNum="18" endNum="20">2. ...</sublesson>
My question: How do I select the first following @startNum?
This formulation
<xsl:value-of select="following::*/@startNum[1] -1"/>
returns this error in Oxygen: Saxon B 9.0.0.6: A sequence of more than one item
is not allowed as the first operand of '-'
Of course, my approach to this problem could be the problem. Perhaps there is a
better approach. I have tried grouping the chapters and lessons first, but the
problem noted above still remains.
Terry
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--