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

Transformation of generic spreadsheet XML

Subject: Transformation of generic spreadsheet XML
From: Xiaocun Xu <xiaocunxu@xxxxxxxxx>
Date: Thu, 19 Apr 2001 05:15:07 -0700 (PDT)
spreadsheet xml
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

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.