[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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 > 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|