-CLASSPATH=$(CLASSBASE):/usr/local/java/saxon-6.4.4/saxon.jar
+CLASSPATH=$(CLASSBASE):/usr/local/java/saxon-6.5.2/saxon.jar
all: $(CLASSFILES)
-@for f in $(SUBDIRS); do \
/** The XHTML namespace name. */
protected static String xhURI = "http://www.w3.org/1999/xhtml";
+ /** The first line number will be <code>startinglinenumber</code>. */
+ protected int startinglinenumber = 1;
+
/** Every <code>modulus</code> line will be numbered. */
protected int modulus = 5;
*/
public NumberLinesEmitter(Controller controller,
NamePool namePool,
+ int startingLineNumber,
int modulus,
int width,
String separator,
firstElement = true;
this.modulus = modulus;
+ this.startinglinenumber = startingLineNumber;
this.width = width;
this.separator = separator;
this.foStylesheet = foStylesheet;
if (lineNumber == 0) {
// The first line is always numbered
- formatLineNumber(++lineNumber);
+ lineNumber = startinglinenumber;
+ formatLineNumber(lineNumber);
}
// Walk through the text node looking for newlines
private static int modulus = 0;
/** The width (in characters) of line numbers (for padding). */
private static int width = 0;
+ /** The starting line number. */
+ private static int startinglinenumber = 1;
/** The separator between the line number and the verbatim text. */
private static String separator = "";
* <dt><code>linenumbering.separator</code></dt>
* <dd>Specifies the string that separates line numbers from lines
* in the program listing. (builtin default: " ").</dd>
+ * <dt><code>linenumbering.startinglinenumber</code></dt>
+ * <dd>Specifies the initial line number
+ * in the program listing. (builtin default: "1").</dd>
* <dt><code>stylesheet.result.type</code></dt>
* <dd>Specifies the stylesheet result type. The value is either 'fo'
* (for XSL Formatting Objects) or it isn't. (builtin default: html).</dd>
// Hardcoded defaults
modulus = 5;
width = 3;
+ startinglinenumber = 1;
separator = " ";
foStylesheet = false;
System.out.println("$linenumbering.width is not a number: " + varString);
}
+ // Get the startinglinenumber
+ varString = getVariable(context, "linenumbering.startinglinenumber");
+ try {
+ startinglinenumber = Integer.parseInt(varString);
+ } catch (NumberFormatException nfe) {
+ System.out.println("$linenumbering.startinglinenumber is not a number: " + varString);
+ }
+
// Get the separator
varString = getVariable(context, "linenumbering.separator");
separator = varString;
NamePool namePool = controller.getNamePool();
NumberLinesEmitter nlEmitter = new NumberLinesEmitter(controller,
namePool,
+ startinglinenumber,
listingModulus,
listingWidth,
separator,
</xsl:choose>
</xsl:variable>
+ <xsl:variable name="linenumbering.startinglinenumber">
+ <xsl:choose>
+ <xsl:when test="@startinglinenumber">
+ <xsl:value-of select="@startinglinenumber"/>
+ </xsl:when>
+ <xsl:when test="@continuation='continues'">
+ <xsl:variable name="lastLine">
+ <xsl:choose>
+ <xsl:when test="self::programlisting">
+ <xsl:call-template name="lastLineNumber">
+ <xsl:with-param name="listings"
+ select="preceding::programlisting[@linenumbering='numbered']"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:when test="self::screen">
+ <xsl:call-template name="lastLineNumber">
+ <xsl:with-param name="listings"
+ select="preceding::screen[@linenumbering='numbered']"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:when test="self::literallayout">
+ <xsl:call-template name="lastLineNumber">
+ <xsl:with-param name="listings"
+ select="preceding::literallayout[@linenumbering='numbered']"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:when test="self::address">
+ <xsl:call-template name="lastLineNumber">
+ <xsl:with-param name="listings"
+ select="preceding::address[@linenumbering='numbered']"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:when test="self::synopsis">
+ <xsl:call-template name="lastLineNumber">
+ <xsl:with-param name="listings"
+ select="preceding::synopsis[@linenumbering='numbered']"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:message>
+ <xsl:text>Unexpected verbatim environment: </xsl:text>
+ <xsl:value-of select="local-name(.)"/>
+ </xsl:message>
+ <xsl:value-of select="0"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <xsl:value-of select="$lastLine + 1"/>
+ </xsl:when>
+ <xsl:otherwise>1</xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
<xsl:choose>
<xsl:when test="function-available('sverb:numberLines')">
<xsl:copy-of select="sverb:numberLines($rtf)"/>
</xsl:choose>
</xsl:template>
+<!-- ======================================================================== -->
+
+<xsl:template name="lastLineNumber">
+ <xsl:param name="listings"/>
+ <xsl:param name="number" select="0"/>
+
+ <xsl:variable name="lines">
+ <xsl:call-template name="countLines">
+ <xsl:with-param name="listing" select="string($listings[1])"/>
+ </xsl:call-template>
+ </xsl:variable>
+
+ <xsl:choose>
+ <xsl:when test="not($listings)">
+ <xsl:value-of select="$number"/>
+ </xsl:when>
+ <xsl:when test="$listings[1]/@startinglinenumber">
+ <xsl:value-of select="$number + $listings[1]/@startinglinenumber + $lines - 1"/>
+ </xsl:when>
+ <xsl:when test="$listings[1]/@continuation='continues'">
+ <xsl:call-template name="lastLineNumber">
+ <xsl:with-param name="listings" select="listings[position() > 1]"/>
+ <xsl:with-param name="number" select="$number + $lines"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$lines"/>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template name="countLines">
+ <xsl:param name="listing"/>
+ <xsl:param name="count" select="1"/>
+
+ <xsl:choose>
+ <xsl:when test="contains($listing, ' ')">
+ <xsl:call-template name="countLines">
+ <xsl:with-param name="listing" select="substring-after($listing, ' ')"/>
+ <xsl:with-param name="count" select="$count + 1"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$count"/>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
</xsl:stylesheet>
</xsl:choose>
</xsl:variable>
+ <xsl:variable name="linenumbering.startinglinenumber">
+ <xsl:choose>
+ <xsl:when test="@startinglinenumber">
+ <xsl:value-of select="@startinglinenumber"/>
+ </xsl:when>
+ <xsl:when test="@continuation='continues'">
+ <xsl:variable name="lastLine">
+ <xsl:choose>
+ <xsl:when test="self::programlisting">
+ <xsl:call-template name="lastLineNumber">
+ <xsl:with-param name="listings"
+ select="preceding::programlisting[@linenumbering='numbered']"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:when test="self::screen">
+ <xsl:call-template name="lastLineNumber">
+ <xsl:with-param name="listings"
+ select="preceding::screen[@linenumbering='numbered']"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:when test="self::literallayout">
+ <xsl:call-template name="lastLineNumber">
+ <xsl:with-param name="listings"
+ select="preceding::literallayout[@linenumbering='numbered']"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:when test="self::address">
+ <xsl:call-template name="lastLineNumber">
+ <xsl:with-param name="listings"
+ select="preceding::address[@linenumbering='numbered']"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:when test="self::synopsis">
+ <xsl:call-template name="lastLineNumber">
+ <xsl:with-param name="listings"
+ select="preceding::synopsis[@linenumbering='numbered']"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:message>
+ <xsl:text>Unexpected verbatim environment: </xsl:text>
+ <xsl:value-of select="local-name(.)"/>
+ </xsl:message>
+ <xsl:value-of select="0"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <xsl:value-of select="$lastLine + 1"/>
+ </xsl:when>
+ <xsl:otherwise>1</xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
<xsl:choose>
<xsl:when test="function-available('sverb:numberLines')">
<xsl:copy-of select="sverb:numberLines($rtf)"/>
</xsl:choose>
</xsl:template>
-</xsl:stylesheet>
+<!-- ======================================================================== -->
+<xsl:template name="lastLineNumber">
+ <xsl:param name="listings"/>
+ <xsl:param name="number" select="0"/>
+
+ <xsl:variable name="lines">
+ <xsl:call-template name="countLines">
+ <xsl:with-param name="listing" select="string($listings[1])"/>
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:choose>
+ <xsl:when test="not($listings)">
+ <xsl:value-of select="$number"/>
+ </xsl:when>
+ <xsl:when test="$listings[1]/@startinglinenumber">
+ <xsl:value-of select="$number + $listings[1]/@startinglinenumber + $lines - 1"/>
+ </xsl:when>
+ <xsl:when test="$listings[1]/@continuation='continues'">
+ <xsl:call-template name="lastLineNumber">
+ <xsl:with-param name="listings" select="listings[position() > 1]"/>
+ <xsl:with-param name="number" select="$number + $lines"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$lines"/>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+<xsl:template name="countLines">
+ <xsl:param name="listing"/>
+ <xsl:param name="count" select="1"/>
+ <xsl:choose>
+ <xsl:when test="contains($listing, ' ')">
+ <xsl:call-template name="countLines">
+ <xsl:with-param name="listing" select="substring-after($listing, ' ')"/>
+ <xsl:with-param name="count" select="$count + 1"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$count"/>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+</xsl:stylesheet>