OZONE Asylum
Forums
CSS - DOM - XHTML - XML - XSL - XSLT
change of column to row in xsl
This page's ID:
28453
Search
QuickChanges
Forums
FAQ
Archives
Register
Edit Post
Who can edit a post?
The poster and administrators may edit a post. The poster can only edit it for a short while after the initial post.
Your User Name:
Your Password:
Login Options:
Remember Me On This Computer
Your Text:
Insert Slimies »
Insert UBB Code »
Close
Last Tag
|
All Tags
UBB Help
Note: I have added a root element doc and changed edocs:d-edocs-timesheet to timesheet in my example so that I did not have to worry about name space issues. The hard part here is catching the unique columns. Your uniqueness is defined by wo-num, wo-line and type-. You can gain access to each unique element by making sure there are no preceding entries with the same three values. Aside: You can think of this as a composite primary key. It is my opinion that you should have a unique identifier to group these, so that you do not have to use a composite key. You can access the unique rows can be done by saying [code]select="doc/timesheet[not(wo-num = preceding::wo-num and wo-line = preceding::wo-line and type- = preceding::type-)]"[code] The above is a great concept that you should add to your list of xslt tools. You will often find yourself in similar situations where you can make good use of the preceding axis to access only the unique values. Once you have isolated these unique rows I throw the values into variables so that I can then easily loop through all of the elements that share this composite key. I used HTML here because that allowed me to easily check my work. The whole file follows. [code]<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <head></head> <body> <table> <thead> <tr> <th>wo-line</th> <th>wo-order</th> <th>type</th> <th>mon</th> <th>tue</th> <th>wed</th> <th>thur</th> <th>fri</th> </tr> </thead> <tbody> <xsl:for-each select="/doc/timesheet[not(wo-num = preceding::wo-num and wo-line = preceding::wo-line and type- = preceding::type-)]"> <xsl:variable name="wo-num" select="wo-num"/> <xsl:variable name="wo-line" select="wo-line"/> <xsl:variable name="type-" select="type-"/> <tr> <td><xsl:value-of select="wo-num"/></td> <td><xsl:value-of select="wo-line"/></td> <td><xsl:value-of select="type-"/></td> <xsl:for-each select="/doc/timesheet[wo-num = $wo-num and wo-line = $wo-line and type- = $type-]"> <td><xsl:value-of select="hours"/></td> </xsl:for-each> </tr> </xsl:for-each> </tbody> </table> </body> </html> </xsl:template> </xsl:stylesheet>[/code] Dan @ [url=http://www.codetown.org]Code Town[/url]
Loading...
Options:
Enable Slimies
Enable Linkwords
« Backwards
—
Onwards »