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: Transformation of generic spreadsheet XML


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 &gt; 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


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