This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Number formatting with <xsl:number />


Ragnar,

>What do I do wrong? Or doesn't the XSLT engine in built-in Xeena support 
><xsl:number>? I thought that was a mandatory element...

There doesn't seem to be anything wrong with your XSLT - it works fine in
SAXON (when an 'l' is added before the ':' in the closing xs:variable tag).
 I don't know if Xeena supports xsl:number - different XSLT processors have
different levels of compliance, and even 'mandatory' elements aren't
supported in some.  The Xeena documentation should tell you what they've
missed out.

A couple of things about your XSLT (though bear in mind that I don't know
what your input looks like or Xeena's proclivities, and you might well be
using the code you're using because of your input or because other code
doesn't work in Xeena):

Firstly, when you set your variable, you want to give '$rowIndex' the value
that is simply the number of preceding 'option' siblings.  When you set a
variable using the *content* of the xsl:variable element, you create a
'result-tree fragment' consisting of a text node with the content
specified.  This is *slightly* more work for the processor to work with
later on than if you set the value of the variable using the 'select'
attribute, which just sets the value of the variable to the (string of the)
number.  In other words, rather than using:

<xsl:variable name="rowIndex">
  <xsl:value-of select="count(preceding-sibling::option)"/>
</xsl:variable>

you should probably use:

<xsl:variable name="rowIndex" select="count(preceding-sibling::option)" />

Secondly, doing anything to do with the axes descendent, preceding,
following, preceding-sibling and following-sibling are generally to be
avoided if at all possible.  I'm not sure what your input looks like: if
the 'option' elements aren't mixed up with other elements inside their
parent, then you can probably simply use position() instead:

<xsl:variable name="rowIndex" select="position()" />

If they *are* mixed up with other elements, then you should still use
position(), but make sure that the current node list contains only the
'option' elements by doing something like:

<xsl:apply-templates select="option" mode="HTML" />

Finally, all this is by the by because when you're using xsl:number it's
*extremely rare* that you need to use its 'value' attribute.  You will
probably be able to simply use:

<xsl:number format="a" />

as this defaults to using the position of the current node (the 'option'
element) in the node list consisting of all the sibling nodes of the same
node type (i.e. elements) that are called the same thing (i.e. the sibling
'option' elements).

So, try the template:

<xsl:template match="option" mode="HTML">
  <TR>
    <TD>
      <xsl:number format="a" />
    </TD>
    <TD>
      further row content
    </TD>
  </TR>
</xsl:template>

I hope that helps,

Jeni

Dr Jeni Tennison
Epistemics Ltd * Strelley Hall * Nottingham * NG8 6PE
tel: 0115 906 1301 * fax: 0115 906 1304 * email: jeni.tennison@epistemics.co.uk


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]