This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Transformation of generic spreadsheet XML
- To: Xiaocun Xu <xiaocunxu at yahoo dot com>
- Subject: Re: [xsl] Transformation of generic spreadsheet XML
- From: Jeni Tennison <mail at jenitennison dot com>
- Date: Thu, 19 Apr 2001 16:01:47 +0100
- CC: xsl-list at lists dot mulberrytech dot com
- Organization: Jeni Tennison Consulting Ltd
- References: <20010419121507.59738.qmail@web11102.mail.yahoo.com>
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi Xiaocun,
> XSL I have so far:
> 1. first capture the header:
> <xsl:template match="row" mode="BidsDetail">
> <xsl:if test="string(cell[1]) = string('BidType')">
> <xsl:variable name="bidHeader" select="."/>
> 2. process each bid from the rows following the
> heading row:
> <xsl:for-each select="following-sibling::row">
> <xsl:element name="Bid">
> <xsl:for-each select="cell">
I think you'd be better off storing the bidHeader row in a global
variable (assuming that the row elements are children of a 'rows'
document element here):
<xsl:variable name="bidHeader" select="/rows/row[1]" />
Then you could apply templates to only the rows after the first row:
<xsl:template match="rows">
<xsl:apply-templates select="row[position() > 1]" />
</xsl:template>
And then have a row-matching template to give the Bid element. Within
that template, apply templates to all the cell elements:
<xsl:template match="row">
<Bid>
<xsl:apply-templates select="cell" />
</Bid>
</xsl:template>
You can then have different templates for cell elements that have a
column attribute greater than 7, and other cell elements. To answer
your question, you can get the relevant cell by comparing its column
attribute to the column attribute of the current cell, which you can
get with:
current()/@column
So the cell-matching templates look like:
<!-- most cells make attributes -->
<xsl:template match="cell">
<xsl:attribute
name="{$bidHeader/cell[@column = current()/@column]}">
<xsl:value-of select="." />
</xsl:attribute>
</xsl:template>
<!-- other cells make ExtendedAttribute elements -->
<xsl:template match="cell[@column > 7]">
<ExtendedAttribute
ExtendedAttributeCode="{$bidHeader/cell[@column = current()/@column]}"
ExtendedAttributeValue="{.}" />
</xsl:template>
I hope that helps,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list