Topic: change of column to row in xsl Pages that link to <a href="https://ozoneasylum.com/backlink?for=28453" title="Pages that link to Topic: change of column to row in xsl" rel="nofollow" >Topic: change of column to row in xsl\

 
Author Thread
purva
Obsessive-Compulsive (I) Inmate

From:
Insane since: Sep 2006

IP logged posted posted 09-20-2006 09:31 Edit Quote

I want to change the Xsl column data to XSL row

eg: i am getting the data output as follows

wo-line wo-order mon tues wed thr fri
**********************************************
7627 0001 8
7627 0001 2
7627 0001 3

eg: I want the the data output as follows

wo-line wo-order mon tues wed thr fri
**********************************************
7627 0001 8 2 3

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

IP logged posted posted 09-20-2006 16:41 Edit Quote

How about you show us the starting XML and what you want the resultant XML to be?

Dan @ Code Town

purva
Obsessive-Compulsive (I) Inmate

From:
Insane since: Sep 2006

IP logged posted posted 09-21-2006 07:18 Edit Quote

The Xml is as follows:

code:
<edocs:d-edocs-timesheet>
			<request-id>900687</request-id>
			<ccn>GEC</ccn>
			<mas-loc>M</mas-loc>
			<dept>5100</dept>
			<emp-num>2128</emp-num>
			<date-day>Monday</date-day>
			<rec-seq>1</rec-seq>
			<emp-name>SELLERS, WAYNE</emp-name>
			<shift>1</shift>
			<wo-num>769247</wo-num>
			<wo-line>0001</wo-line>
			<type->R</type->
			<hours>8</hours>
			<operation>  20</operation>
			<comp-qty>122</comp-qty>
		</edocs:d-edocs-timesheet>
		<edocs:d-edocs-timesheet>
			<request-id>900687</request-id>
			<ccn>GEC</ccn>
			<mas-loc>M</mas-loc>
			<dept>5100</dept>
			<emp-num>2128</emp-num>
			<date-day>Monday</date-day>
			<rec-seq>2</rec-seq>
			<emp-name>SELLERS, WAYNE</emp-name>
			<shift>1</shift>
			<wo-num>769247</wo-num>
			<wo-line>0001</wo-line>
			<type->O</type->
			<hours>2</hours>
			<operation>  20</operation>
			<comp-qty>30</comp-qty>
		</edocs:d-edocs-timesheet>
		<edocs:d-edocs-timesheet>
			<request-id>900687</request-id>
			<ccn>GEC</ccn>
			<mas-loc>M</mas-loc>
			<dept>5100</dept>
			<emp-num>2128</emp-num>
			<date-day>Tuesday</date-day>
			<rec-seq>3</rec-seq>
			<emp-name>SELLERS, WAYNE</emp-name>
			<shift>1</shift>
			<wo-num>769247</wo-num>
			<wo-line>0001</wo-line>
			<type->R</type->
			<hours>3</hours>
			<operation>  20</operation>
			<comp-qty>10</comp-qty>
		</edocs:d-edocs-timesheet>





the above xml gives me the data o/p as follows:


code:
wo-line  wo-order    type          mon          tues       wed thr fri
******  *******   *****          ****     ******   ***********************
  769247    0001          R              8
  769247    0001          R                                2
  769247    0001          O              2




I want the data o/p format to be

code:
wo-line  wo-order    type          mon          tues       wed thr fri
******  *******   *****          ****     ******   ***********************
  769247    0001          R              8                2
  769247    0001          O              2



Cud u plzzzzzzz help me with the same.....

Regards,

Purva

<edit>Making your code more readable</edit>

(Edited by WarMage on 09-21-2006 14:35)

_Mauro
Maniac (V) Inmate

From:
Insane since: Jul 2005

IP logged posted posted 09-21-2006 14:52 Edit Quote

The xsl. Somewhere in your xsl code, you got a template that maps "stuff" to cols. xsl:template tags. Check the ones that match the "col" structure in your final xhtml document. And change the xhtml inside that.

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

IP logged posted posted 09-21-2006 15:01 Edit Quote

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>



Dan @ Code Town



Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu