[xsl] Simple list numbering problem with rule based stylesheet approach

Subject: [xsl] Simple list numbering problem with rule based stylesheet approach
From: Jacobus Reyneke <jacobusreyneke@xxxxxxxxx>
Date: Thu, 22 Apr 2010 17:49:55 +0200
Good day,

I'm just looking for a bit of mentoring advice if somebody has a
moment to help. This is more of a "how to do it right" than just a
"how to do it" question.

My biggest problem with XSLT is combining different stylesheet
pattens, such as rule based and navigational based. I'm curretnly
stuck on how to extend the stylesheet below to one that allows
numbered items also.

Input XML:
<gl:list>
   <gl:item>Select province: Western Cape</gl:item>
   <gl:item>Select Town: Cape Town</gl:item>
   <gl:item>Property Type: House</gl:item>
   <gl:item>Min Price: 500 000</gl:item>
   <gl:item>Max Price: 1000 000</gl:item>
</gl:list>

Current XSL:
    <xsl:template match="gl:list">
        <fo:list-block>
            <xsl:apply-templates select="gl:item"/>
        </fo:list-block>
    </xsl:template>
    <xsl:template match="gl:item">
        <xsl:variable/>
        <fo:list-item margin-left="20">
            <fo:list-item-label end-indent="label-end()">
                <fo:block font-family="ZapfDingbats">b</fo:block>
            </fo:list-item-label>
            <fo:list-item-body start-indent="body-start()">
                <fo:block>
                    <xsl:apply-templates/>
                </fo:block>
            </fo:list-item-body>
        </fo:list-item>
    </xsl:template>

The output of this currently puts little check marks next to each list item.

I would like to support a new type of element, lets call it
<gl:numbered-item> which will have the item number instead of a check
box in front of it. So for each list with numbered items in it, the
XSL will need to calculate the position of the sibling under the
parent list. Can and should this be done that way? Is the rule based
template approach the right way to do this type of thing, or am I
writing bad code? I get the feeling I should approach this differently
with a for-each type of solution, but did not want to tackle lists one
way for numbered items an another way for bulleted items.

I'm trying to get into the habit of writing re-usable, extendable and
modular XSL, but it's just me, myself and a bunch of text books alone
on a farm, so sometimes I wonder if I'm not barking up the wrong tree.

Kind regards,
Jacobus
--
"Trust God"
"Be good, be nice, be happy"
"Sleep like a dolphin"

Current Thread