[xsl] Transformation of generic spreadsheet XML

Subject: [xsl] Transformation of generic spreadsheet XML
From: Xiaocun Xu <xiaocunxu@xxxxxxxxx>
Date: Thu, 19 Apr 2001 05:15:07 -0700 (PDT)
Hi,

	I am having some problem transforming generic
spreadsheet XML into XML format I need.  The source
and desired target XML are shown below:

source XML:
  <row>
    <cell column="1">BidType</cell>
    <cell column="2">LineItemCode</cell>
    <cell column="3">SupplierItemCode</cell>
    <cell column="4">Minimum</cell>
    <cell column="5">Maximum</cell>
    <cell column="6">PricePerUnit</cell>
    <cell column="7">OneTimeCharge</cell>
    <cell column="8">Color</cell>
    <cell column="9">Size</cell>
  </row>
  <row>
    <cell column="1">simple</cell>
    <cell column="2">AC74.000.101</cell>
    <cell column="3">3.1</cell>
    <cell column="6">400</cell>
    <cell column="8">blue</cell>
    <cell column="9">x-large</cell>
  </row>...

desired target XML:
<Bid BidType="simple" LineItemCode="AC74.000.101"
SupplierItemCode="3.1" PricePerUnit="400">
	<ExtendedAttribute ExtendedAttributeCode="Color"
ExtendedAttributeValue="blue"/>
	<ExtendedAttribute ExtendedAttributeCode="Size"
ExtendedAttributeValue="x-large"/>
</Bid>

In general, what I need are:
1. For the first row, the first 7 columns are fixed
attributes, and therefore need to be transformed into
attribute names for Bid element.
2. For the first row, all columns after the 7th column
are extended attributes, and therefore need to be
transformed into ExtendedAttribute elements.
3. All rows after the first row will fill in for the
appropriate values according to the column attribute.

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">
3. use xsl:choose to separate out columns greater than
7 and add them as ExtendedAttributes, otherwise Bid
attributes:
	<xsl:choose>
		<xsl:when test="@column &gt; 7">
			<xsl:element name="ExtendedAttribute">
				<xsl:attribute name="ExtendedAttributeCode">
					<xsl:value-of
select="$bidHeader/cell[position()]"/>
				</xsl:attribute>
				<xsl:attribute name="ExtendedAttributeValue">
					<xsl:value-of select="."/>
				</xsl:attribute>
			</xsl:element>
		</xsl:when>
		<xsl:otherwise>
			<xsl:attribute
name="{$bidHeader/cell[position()]}">
				<xsl:value-of select="."/>
			</xsl:attribute>
		</xsl:otherwise>	
	</xsl:choose>

The problem:
$bidHeader/cell[position()] I inserted for the
xsl:value-of are obviously incorrect, since what I
really want is: $bidHeader/cell where cell/@column
equals current @column.  How could I get that result?

Much thanks,

Xiaocun Xu


__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread