This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: Getting max attribute value of an element by attribute value...
- From: "Brinkman, Theodore" <Theodore dot Brinkman at standardregister dot com>
- To: "'xsl-list at lists dot mulberrytech dot com'" <xsl-list at lists dot mulberrytech dot com>
- Date: Wed, 28 Nov 2001 11:54:18 -0500
- Subject: RE: [xsl] Getting max attribute value of an element by attribute value...
- Reply-to: xsl-list at lists dot mulberrytech dot com
I've got another question involving the same block of XML. The following
template USED to work, but now $total = NaN, and I can't figure out why.
XSL
- - - - -
<xsl:template name="hitPoints">
<xsl:variable name="base" select="sum(classes/class/@hp)"/>
<xsl:variable name="mod"><xsl:call-template
name="conMod"/></xsl:variable>
<xsl:variable name="level" select="count(classes/class)"/>
<xsl:variable name="tough"
select="count(feats/feat[normalize-space(@name) = 'Toughness'])"/>
<xsl:variable name="total" select="$base + ($mod * $level) + ($tough
* 3)"/>
<xsl:value-of select="$total"/> = <xsl:value-of select="$base"/> +
(<xsl:value-of select="$mod"/> * <xsl:value-of select="$level"/>) +
(<xsl:value-of select="$tough"/> * 3)
</xsl:template>
- - - - -
XML
- - - - -
<classes>
<class name="Fighter" short="Ftr" level="1" hp="10"
uri="../class/fighter.xml"/>
<class name="Rogue" short="Rog" level="1" hp="3"
uri="../class/rogue.xml"/>
<class name="Fighter" short="Ftr" level="2" hp="5"
uri="../class/fighter.xml"/>
</classes>
- - - - -
<xml:call-template name="hitPoints"/> should return:
26 = 17 + (+2 * 3) + (1 * 3)
But instead I get:
NaN = 17 + (+2 * 3) + (1 * 3)
All of the xsl:call-template calls within hitPoints return the proper
values. What am I missing here?
- Theo
-----Original Message-----
From: cutlass [mailto:cutlass@secure0.com]
Sent: Wednesday, November 28, 2001 10:08 AM
To: xsl-list@lists.mulberrytech.com
Subject: Re: [xsl] Getting max attribute value of an element by
attribute value...
sorry dyslexia kicking in ( replace preceding with following:: )
hehe
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:variable name="test" select="//class"/>
<xsl:for-each select="/classes/class">
<xsl:sort select="@short"/>
<xsl:sort data-type="number" order="ascending" />
<xsl:if test="not(@short = following::class/@short)">
<xsl:value-of select="@short"/>(<xsl:value-of select="@level"/>)<xsl:if
test="not(position() = last())">, </xsl:if>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
cheerse, jim fuller
----- Original Message -----
From: "Brinkman, Theodore" <Theodore.Brinkman@standardregister.com>
To: <xsl-list@lists.mulberrytech.com>
Sent: Wednesday, November 28, 2001 2:34 PM
Subject: [xsl] Getting max attribute value of an element by attribute
value...
> I have the following substructure in an XML file I'm working with.
>
> <classes>
> <class name="Fighter" short="Ftr" level="1" hp="10"
> uri="../class/fighter.xml"/>
> <class name="Rogue" short="Rog" level="1" hp="3"
> uri="../class/rogue.xml"/>
> <class name="Fighter" short="Ftr" level="2" hp="5"
> uri="../class/fighter.xml"/>
> </classes>
>
>
> I'm trying to get this as the output.
>
> Ftr(2), Rog(1)
>
>
> Currently, I can only figure out how to get this:
>
> Ftr(1), Rog(1), Ftr(2)
>
>
> The template I'm using currently stands as:
>
> <xsl:template name="listClasses">
> <xsl:for-each select="classes/class">
> <xsl:value-of select="@short"/>(<xsl:value-of
> select="@level"/>)<xsl:if test="not(position() = last())">, </xsl:if>
> </xsl:for-each>
> </xsl:template>
>
>
> How can I change the template to sort the <class>es so they are all
grouped
> with the first appearance of the class, and I only get the highest level
of
> the class inside the parenthesis?
>
> - Theo
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list