Re: [xsl] Transformation of generic spreadsheet XML

Subject: Re: [xsl] Transformation of generic spreadsheet XML
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Thu, 19 Apr 2001 16:01:47 +0100
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]" />

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">
      <xsl:apply-templates select="cell" />

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:


So the cell-matching templates look like:

<!-- most cells make attributes -->
<xsl:template match="cell">
         name="{$bidHeader/cell[@column = current()/@column]}">
      <xsl:value-of select="." />

<!-- other cells make ExtendedAttribute elements -->
<xsl:template match="cell[@column &gt; 7]">
      ExtendedAttributeCode="{$bidHeader/cell[@column = current()/@column]}"
      ExtendedAttributeValue="{.}" />

I hope that helps,


Jeni Tennison

 XSL-List info and archive:

Current Thread