Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

is it doable ?

Status
Not open for further replies.

tyris

Programmer
Nov 2, 2000
311
FR
my XML structure is this way :

Code:
	<BudgetItemXML>
		<Service>Publishing</Service>
		<Category>DTP</Category>
		<BIT>item 3  </BIT>
		<PC>PubDTPPage</PC>
		</BudgetItemXML>
	<BudgetItemXML>
	<BudgetItemXML>
		<Service>Translation</Service>
		<Category>Other translation</Category>
		<BIT>test 2       </BIT>
		<PC>XltTranslatorHour</PC>
		</BudgetItemXML>
	<BudgetItemXML>
		<Service>Translation</Service>
		<Category>Software translation</Category>
		<BIT>test 1       </BIT>
		<PC>XltSoftwareWord</PC>
	</BudgetItemXML>
	<BudgetItemXML>
		<Service>Translation</Service>
		<Category>Software translation</Category>
		<BIT>test 4      </BIT>
		<PC>XltSoftwareWord</PC>
	</BudgetItemXML>

as i'm not a XLST guru i'd like to know if with this XML it's doable (in a quite simple way) to get an output sorted by Service and then category with the XSLT transformation (this way :)


Service : Translation
Category : Other translation
test 2 - XltTranslatorHour
Category : Software translation
test 1 - XltSoftwareWord
test 4 - XltSoftwareWord

Service : Publishing
Category : DTP
item 3 - PubDTPPage




Best regards,
Elise, XML learning girl X-)
 
so, you want to sort do you?

You need to specify in the <xsl:apply-templates > template the element you want to sort by in an xsl:sort tag..

eg
<xsl:apply-templates select=&quot;&quot;>
<xsl:sort case-order=&quot;upper-first&quot; data-type=&quot;text&quot; order=&quot;ascending&quot; select=&quot;&quot;/>
</xsl:apply-templates>


it also looks like category and service exist on the same 'level' - ie they are siblings. you will need to apply relative xpath syntax when getting the values of sibling nodes, ie (assuming we are applying the template &quot;//Service&quot;):

<xsl:value-of select=&quot;../Category&quot;/>

I would have given you a whole solution, however since you are the XML learning girl I thought u might want to look into these thigns in more depth ;)


hope that points you in the right direction.

m@
 
tyris & flumpy:

I'm also quite new to XSL/XML, and this problem piqued my curiosity. I decided to use this for practice/learning as it looked relatively easy. Ahh, appearances can be deceiving! Several hours and many approaches later, I still didn't have a solution. After a little more investigation, I've discovered that grouping data using XSL isn't all that straight forward. I still don't have the solution (sorry, tyris), but here are some links that I found that may prove helpful:




I just found these links late last night, so I haven't had time to fully evaluate them or re-tackle the problem using their suggestions. But, when I have some time this weekend, I'm going give it another try.

flumpy, if you have any other input on this type of problem, I'd love to see it.

cheers!
<xsl:value-of select=&quot;kubu&quot; />
 
I am also still learning these stuff. Can you please post the code here?

I've looked at the site and tried the code advised on the post but I am not getting any result. Also, the format of the XML I'm using is the one that you retrieve from an ADO recordset through a stream using adPersistXML as option for saving. Hence I'm dealing with <z:row> as data nodes with the fields as attributes. However, I'd like to group based on more that one attribute (say @FIELD1 and within @FIELD1, @FIELD2) when I do my transformation so I can get something like this:

<DATASET>
<FIELD1>
<FIELD1_DATA>1</FIELD1_DATA>
<FIELD2>
<FIELD2_DATA>1</FIELD2_DATA>
<GROUPED>
<GROUP_DATA1>G1</GROUP_DATA1>
<GROUP_DATA2>G2</GROUP_DATA2>
</GROUPED>
<GROUPED>
<GROUP_DATA1>G3</GROUP_DATA1>
<GROUP_DATA2>G4</GROUP_DATA2>
</GROUPED>
</FIELD2>
<FIELD2>
<FIELD2_DATA>2</FIELD2_DATA>
<GROUPED>
<GROUP_DATA1>G5</GROUP_DATA1>
<GROUP_DATA2>G6</GROUP_DATA2>
</GROUPED>
</FIELD2>
</FIELD1>
<FIELD1>
<FIELD1_DATA>2</FIELD1_DATA>
<FIELD2>
<FIELD2_DATA>3</FIELD2_DATA>
<GROUPED>
<GROUP_DATA1>G7</GROUP_DATA1>
<GROUP_DATA2>G8</GROUP_DATA2>
</GROUPED>
<GROUPED>
<GROUP_DATA1>G9</GROUP_DATA1>
<GROUP_DATA2>G10</GROUP_DATA2>
</GROUPED>
</FIELD2>
</FIELD1>
</DATASET>

Thanks,
Gene Cardenio
 
i post a sample code. I made this many months before, i remember i had to modify the XML structre to fit a bit more with the grouping.

Code:
<!--
     File:          temp.xsl
     Author:     Elise Dupont 07/02/2002
     Desc:       Transform xml into quote where catagorisation is choosable
-->
  <xsl:stylesheet version=&quot;1.0&quot;
                  xmlns:xsl=&quot;[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform&quot;[/URL]
                  xmlns=&quot;urn:schemas-microsoft-com:xml-data&quot;>
<xsl:output method=&quot;html&quot; indent=&quot;yes&quot;/>
<xsl:key name=&quot;item-by-id&quot; match=&quot;BudgetItemXML&quot; use=&quot;BIT_ItemID&quot; />
<xsl:key name=&quot;item-by-cat&quot; match=&quot;BudgetItemXML&quot; use=&quot;CAT_CategoryName&quot; />
<xsl:key name=&quot;item-by-service&quot; match=&quot;BudgetItemXML&quot; use=&quot;SERV_ServiceName&quot; />
<xsl:key name=&quot;item-by-service-id&quot; match=&quot;BudgetItemXML&quot; use=&quot;concat(SERV_ServiceName, ' ',BIT_ItemID)&quot; />
<xsl:key name=&quot;item-by-id-service&quot; match=&quot;BudgetItemXML&quot; use=&quot;concat(BIT_ItemID, ' ',SERV_ServiceName)&quot; />
<xsl:key name=&quot;item-by-service-cat&quot; match=&quot;BudgetItemXML&quot; use=&quot;concat(SERV_ServiceName, ' ', CAT_CategoryName)&quot; />
<xsl:key name=&quot;item-by-id-service-cat&quot; match=&quot;BudgetItemXML&quot; use=&quot;concat(BIT_ItemID, ' ', SERV_ServiceName,' ',CAT_CategoryName)&quot; />
<xsl:key name=&quot;item-by-service-id-cat&quot; match=&quot;BudgetItemXML&quot; use=&quot;concat(SERV_ServiceName,' ',BIT_ItemID, ' ', CAT_CategoryName)&quot; />
<xsl:key name=&quot;item-by-service-cat-id&quot; match=&quot;BudgetItemXML&quot; use=&quot;concat(SERV_ServiceName, ' ', CAT_CategoryName,' ',BIT_ItemID)&quot; />

<xsl:template match=&quot;dsBudget&quot;>
<html>
<head>
	<title>Untitled</title>
</head>
<body>
<table cellspacing=&quot;0&quot;>
<tr>
	<td>
		<IMG height=&quot;45&quot; src=&quot;D:\backup\My Documents Boulot\devp\Quotation\XML transformation\logo.jpg&quot; width=&quot;150&quot; border=&quot;0&quot;/>
	</td>
	<td>
		<table cellspacing=&quot;0&quot;>        
        <TR>
			<td bgcolor=&quot;#000080&quot; height=&quot;45&quot;>
				<table style=&quot;color: White;&quot; cellspacing=&quot;0&quot;>
				<tr>
					<td width=&quot;100&quot; >Client: </td>
					<td width=&quot;100&quot; style=&quot;FONT-WEIGHT: bold&quot;><xsl:value-of select=&quot;/*/*[1]/*[6]&quot; /></td>
					<td width=&quot;100&quot; >Quotation #: </td>
					<td width=&quot;100&quot; style=&quot;FONT-WEIGHT: bold&quot;><xsl:value-of select=&quot;/*/*[1]/*[1]&quot; /></td>
					<td width=&quot;100&quot;>Date: </td>
					<td width=&quot;100&quot; style=&quot;FONT-WEIGHT: bold&quot;><xsl:value-of select=&quot;/*/*[1]/*[5]&quot; /></td>
				</tr>
				<tr>
					<td>Project: </td>
					<td style=&quot;FONT-WEIGHT: bold&quot;></td>
					<td>Project Code: </td>
					<td style=&quot;FONT-WEIGHT: bold&quot;><xsl:value-of select=&quot;/*/*[1]/*[7]&quot; /></td>
					<td>Author: </td>
					<td style=&quot;FONT-WEIGHT: bold&quot;><xsl:value-of select=&quot;/*/*[1]/*[4]&quot; /></td>
				</tr>
				</table>   
			</td>
	  </TR>
	  </table>
	  </td>
</tr>
</table>
Quote Done in <xsl:value-of select=&quot;/*/*[1]/*[3]&quot; />
<TABLE border=&quot;0&quot; cellspacing=&quot;0&quot;>
	<TR bgcolor=&quot;#000080&quot; style=&quot;color: White;&quot; border=&quot;1&quot;>
		<TD width=&quot;100&quot; border=&quot;1&quot;>Task</TD>
		<TD width=&quot;100&quot; border=&quot;1&quot;>Activity</TD>
		<TD width=&quot;100&quot; border=&quot;1&quot;>Quote Item</TD>
		<TD width=&quot;100&quot; border=&quot;1&quot;>PriceCode</TD>
		<TD width=&quot;50&quot; border=&quot;1&quot;>Unit</TD>
		<xsl:for-each select=&quot;BudgetLangXML&quot;>
		<td >
		<TABLE border=&quot;1&quot; cellspacing=&quot;0&quot; >
		<TR bgcolor=&quot;#000080&quot; style=&quot;color: White;&quot;>
			<TD width=&quot;150&quot; colspan=&quot;3&quot;><xsl:value-of select=&quot;LANGS_Name&quot; /> /  <xsl:value-of select=&quot;LangName&quot; /></TD>
		</TR>
		<TR bgcolor=&quot;#000080&quot; style=&quot;color: White;&quot;>
			<TD width=&quot;50&quot; >Qty</TD>
			<TD width=&quot;50&quot; >Unit Price</TD>
			<TD width=&quot;50&quot; >Total</TD>
		</TR>		
		</TABLE>
		</td>
		</xsl:for-each>
	</TR>	
	<xsl:for-each select=&quot;BudgetItemXML[count(. | key('item-by-service', SERV_ServiceName)[1]) = 1]&quot;>
		<TR>
			<TD width=&quot;100&quot;><xsl:value-of select=&quot;SERV_ServiceName&quot; /></TD>
		</TR>
		
	<!--
	<xsl:for-each select=&quot;BudgetItemXML[count(. | key('item-by-id', BIT_ItemID)[1]) = 1]&quot;>
	<xsl:variable name=&quot;id_items&quot; select=&quot;key('item-by-service', SERV_ServiceName)&quot; />
	 <xsl:for-each  select=&quot;$id_items[generate-id() =generate-id(key('item-by-service-id',concat(SERV_ServiceName, ' ',BIT_ItemID))[1])]&quot;>
	-->

			<xsl:variable name=&quot;service_items&quot; select=&quot;key('item-by-service', SERV_ServiceName)&quot; />
 			<xsl:for-each  select=&quot;$service_items[generate-id() =generate-id(key('item-by-service-cat',concat(SERV_ServiceName, ' ', CAT_CategoryName))[1])]&quot;>
				<TR>
		              	<TD width=&quot;100&quot; bgcolor=&quot;#E5E5E5&quot;></TD>
					<TD width=&quot;100&quot;><xsl:value-of select=&quot;CAT_CategoryName&quot; /></TD>
				</TR>
				<xsl:variable name=&quot;id_items&quot; select=&quot;key('item-by-cat', CAT_CategoryName)&quot; />
				 <xsl:for-each  select=&quot;$id_items[generate-id() =generate-id(key('item-by-service-cat-id',concat(SERV_ServiceName, ' ', CAT_CategoryName,' ',BIT_ItemID))[1])]&quot;>
				<TR>
					<TD width=&quot;100&quot; bgcolor=&quot;#E5E5E5&quot;></TD>
					<TD width=&quot;100&quot; bgcolor=&quot;#E5E5E5&quot;></TD>
					<TD width=&quot;100&quot;><xsl:value-of select=&quot;BIT_ItemName&quot; /> </TD>
					<TD width=&quot;100&quot;><xsl:value-of select=&quot;PC_PriceCodeName&quot; /></TD>
					<TD width=&quot;50&quot;><xsl:value-of select=&quot;UNI_Name&quot; /> </TD>
					
					<xsl:for-each  select=&quot;$service_items[generate-id() =generate-id(key('item-by-service-cat',concat(SERV_ServiceName, ' ', CAT_CategoryName))[1])]&quot;>
					<td>
					<table cellspacing=&quot;0&quot;>
						<td width=&quot;50&quot; align=&quot;center&quot;><xsl:value-of select=&quot;BIT_ItemNbSell&quot; /></td>
						<td width=&quot;50&quot; align=&quot;center&quot;><xsl:value-of select=&quot;PLD_Price&quot; /></td>
						<td width=&quot;50&quot; align=&quot;center&quot;><xsl:value-of select=&quot;Total&quot; /></td>
					</table>
					</td>
					</xsl:for-each>
				</TR>
				</xsl:for-each>
				</xsl:for-each>
		</xsl:for-each>
</TABLE>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Best regards,
Elise, XML girl X-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top