[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Adding Several Numerical Attribute Values into One At

Subject: Adding Several Numerical Attribute Values into One Attribute
From: "Joe Heidenreich" <HeidenreichJ@xxxxxxxx>
Date: Mon, 11 Jul 2005 09:03:02 -0400
xsl adding values
Hi,

I'm trying to translate an xml table into html and I want to offset the
table head with a horizontal rule that spans the entire width of the
table.
So I need to generate a colspan attribute value that consists of all
other colspan attribute values.
If the colspan attribute is missing or "NaN", add one to the value.
I also have to use XML 1.0.

For example:

<tr>
	<th colspan="1"></th>
	<th colspan="2"></th>
	<th colspan="NaN"></th>
</tr>

I would need a colspan attribute that contains the value of 4.

I know that variables and parameters in XSLT don't work the same as a
coder is used to. I've looked at a few examples that simulate an
incrementing variable through a parameter so you can process a loop,
which I believe to be a similar situation to the one that I'm dealing
with, except I need to add a variant value depending on the attribute.

Here is an example of my XSL that doesn't work:

<xsl:template match="thead">
		<tr>
			<td>
				<xsl:attribute
name="colspan"><xsl:call-template name="get-col-span"/></xsl:attribute>
				<hr noshade="noshade"/>
			</td>
		</tr>
	<xsl:apply-templates/>
</xsl:template>

<xsl:template name="get-col-span">
	<xsl:apply-templates select="tr[1]" mode="build-col-span"/>
</xsl:template>

<xsl:template match="tr" mode="build-col-span">
	<xsl:param name="colspan_var"/>
	<xsl:call-template name="get-th">
		<xsl:with-param name="colspan_var">0</xsl:with-param>
	</xsl:call-template>
</xsl:template>

<xsl:template match="th" name="get-th">
	<xsl:choose>
		<xsl:when test="@colspan != ''">
			<xsl:choose>
				<xsl:when test="@colspan != 'NaN'">
					<xsl:param name="colspan_var"
select="$colspan_var + @colspan"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:param name="colspan_var"
select="$colspan_var + 1"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:when>
		<xsl:otherwise>
			<xsl:param name="colspan_var"
select="$colspan_var + 1"/>
		</xsl:otherwise>
	</xsl:choose>

	<xsl:variable name="next" select="following-sibling::th[1]"/>
	<xsl:choose>
		<xsl:when test="!($next)">
			<xsl:value-of select="$colspan_var"/>
		</xsl:when>
		<xsl:otherwise>
			<xsl:call-template name="get-th">
				<xsl:with-param
name="colspan_var"><xsl:value-of
select="$colspan_var"/></xsl:with-param>
			</xsl:call-template>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

I know there is a problem with how I'm setting up my parameter value in
the get-th template. I'm not even sure if I'm addressing this problem in
the proper manner. Any help would be greatly appreciated. Thanks!

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.