You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by Ralf Heydenreich <rh...@HTWM.De> on 2004/10/27 15:54:34 UTC

creating an index page

Hi all,
I'm using AurigaDoclet for creating a PDF version of JavaDoc from my java
sources. This doclet uses XSL-FO for doing this. There is a XSL stylesheet
for converting the resulting XML to FO. This XSL contains some information
about creating an index page, but unfortunately every entry is placed on a
single row (even equal entries). Now I've tried to correct the stylesheet,
but it doesn't work. I have introduced a global variable (oldentry) which
stores the old entry for each item. If the template is called repeatedly,
it tests for the value of oldentry and if it is equal to the actual entry,
then a simple comma followed by the new page number should be printed. If
not, a new row should be printed. But none of this happens. Can anyone
tell me what's wrong?
I used this code:

<!--
*************************************************************************
This template generates the index
*************************************************************************
-->
<xsl:template name="generate-index">
<xsl:param name="alphas" select="$upper-alphas" />
<xsl:if test="not($alphas = '')">
<xsl:call-template name="display-index-items">
	<xsl:with-param name="alphabet" select="substring($alphas, 1, 1)" />
</xsl:call-template>
<xsl:call-template name="generate-index">
	<xsl:with-param name="alphas" select="substring($alphas, 2)" />
</xsl:call-template>
</xsl:if>
</xsl:template>

<!--
*************************************************************************
This template generates the index
*************************************************************************
-->
<xsl:template name="display-index-items">
<xsl:param name="alphabet" />
<xsl:variable name="lower-alphabet">
<xsl:call-template name="to-lower-case">
	<xsl:with-param name="str" select="$alphabet" />
</xsl:call-template>
</xsl:variable>
<xsl:if test="key('index-key', $alphabet) or key('index-key',
$lower-alphabet)">
<fo:table table-layout="fixed" width="100%">
<fo:table-column column-width="proportional-column-width(1)"/>
<fo:table-body>
<fo:table-row>
<fo:table-cell>
<fo:block start-indent="0.25in" space-before="10pt" space-after="5pt"
font-size="14pt" font-weight="bold">
	<xsl:value-of select="$alphabet" />
</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row keep-with-previous="always">
<fo:table-cell>
<!-- starting with lower alphabet -->
<xsl:for-each select="key('index-key', $lower-alphabet)">
	<xsl:sort select="@name" case-order="lower-first"/>
	<xsl:call-template name="display-index-item">
		<xsl:with-param name="item" select="." />
	</xsl:call-template>
</xsl:for-each>
<!-- starting with upper alphabet -->
<xsl:for-each select="key('index-key', $alphabet)">
<xsl:sort select="@name" />
<xsl:call-template name="display-index-item">
	<xsl:with-param name="item" select="." />
</xsl:call-template>
</xsl:for-each>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</xsl:if>
</xsl:template>

<!--
*************************************************************************
This template renders a single index item.
*************************************************************************
-->
<xsl:template name="display-index-item">
<xsl:param name="item" />
<xsl:variable name="local-name" select="local-name($item)" />
<xsl:variable name="target">
	<xsl:choose>
	<xsl:when test="$local-name = 'class'">
		<xsl:value-of select="$item/@qualified-name" />
	</xsl:when>
	<xsl:when test="$local-name = 'method' or $local-name = 'constructor'">
		<xsl:value-of
			select="concat($item/parent::class/@qualified-name, $item/@name,
$item/@signature)" />
	</xsl:when>
	<xsl:when test="$local-name = 'field'">
		<xsl:value-of
			select="concat($item/parent::class/@qualified-name, '_field_',
$item/@name)" />
	</xsl:when>
</xsl:choose>
</xsl:variable>
<fo:block start-indent="0.5in">
	<xsl:choose>
	<xsl:when test="$generate-links = 'true'">
	   <xsl:if test="$oldentry != $item/@name">
			<fo:basic-link internal-destination="{$target}">
				<xsl:call-template name="get-css-for-element">
					<xsl:with-param name="element">a</xsl:with-param>
				</xsl:call-template>
				<xsl:value-of select="$item/@name" />
			</fo:basic-link>
			<xsl:text> ... </xsl:text>
		</xsl:if>
	   <xsl:if test="$oldentry = $item/@name">
			<xsl:text>, </xsl:text>
		</xsl:if>
		<fo:inline font-style="italic">
			<fo:page-number-citation ref-id="{$target}" />
		</fo:inline>
	</xsl:when>
	<xsl:otherwise>
			<xsl:value-of select="$item/@name" /><xsl:text> ... </xsl:text>
			<fo:inline font-style="italic">
				<fo:page-number-citation ref-id="{$target}" />
			</fo:inline>
	</xsl:otherwise>
	</xsl:choose>
</fo:block>
<xsl:variable name="oldentry"><xsl:value-of select="$item/@name" />
</xsl:variable>
</xsl:template>


TIA,

Ralf Heydenreich
_______________________________________________________[RH]___

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-user-help@xml.apache.org


Re: creating an index page

Posted by "J.Pietschmann" <j3...@yahoo.de>.
Ralf Heydenreich wrote:
> Hi all,
> I'm using AurigaDoclet for creating a PDF version of JavaDoc from my java
> sources. This doclet uses XSL-FO for doing this. There is a XSL stylesheet
> for converting the resulting XML to FO. This XSL contains some information
> about creating an index page, but unfortunately every entry is placed on a
> single row (even equal entries). Now I've tried to correct the stylesheet,
> but it doesn't work. I have introduced a global variable (oldentry) which
> stores the old entry for each item. If the template is called repeatedly,
> it tests for the value of oldentry and if it is equal to the actual entry,
> then a simple comma followed by the new page number should be printed. If
> not, a new row should be printed. But none of this happens. Can anyone
> tell me what's wrong?

It seems you try grouping, but the usual wrong way. XSLT variables
cannot be reassigned.
Check the XSLT FAQ:
  http://www.dpawson.co.uk/xsl/sect2/N4486.html
and Jeni's pages about this topic:
  http://www.jenitennison.com/xslt/grouping/index.html
Ask on the XSL list for more help.

J.Pietschmann

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-user-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-user-help@xml.apache.org