Subject: [xsl] need help for sum() and point of view From: Elise_Dupont@xxxxxxxxxxxxxx Date: Wed, 3 Jul 2002 16:47:12 +0200 |
hi, I made some work on a XML file to translate it. I would like first to have your point of view : look at the transformation of the following XML by the following XSL you can see 2 buttons in fact those buttons should do this : by default the grouping is made first by Task and then by Activity but if the user click on the button this should swap the grouping with first Activity and then Task. Do you think it's doable ? (maybe with javascript included in the web page, loading xml using xml dom and data island ... ?) Second question : i need some help for the sum() because i still have difficulties with paths and things like this... the best would be a solution + explanation but i think that i could maybe try to do it myself with a sample of "complex" sum() TIA regards, Elise, XML learning girl ;-) XML FILE : ------------------------------------------------------------------------------------------------- <?xml version="1.0" standalone="yes"?> <?xml-stylesheet type="text/xsl" href="temp.xsl"?> <dsBudget xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <BudgetHeaderXML> <BUD_Number>QT3CDTE02000 </BUD_Number> <BUD_Name>Quote Opened 1</BUD_Name> <CUR_Name>Israel (Shekel)</CUR_Name> <BUD_CreatedBy>elise</BUD_CreatedBy> <BUD_CreationDate>2001-12-13T00:00:00.0000000+01:00</ BUD_CreationDate> <COMP_Name>3COM</COMP_Name> <PRJ_CODE>tutu </PRJ_CODE> </BudgetHeaderXML> <BudgetLangXML> <LANGS_Name>Arabic</LANGS_Name> <LangName>English (UK)</LangName> </BudgetLangXML> <BudgetLangXML> <LANGS_Name>Danish</LANGS_Name> <LangName>Norwegian</LangName> </BudgetLangXML> <BudgetLangXML> <LANGS_Name>English</LANGS_Name> <LangName>Swedish</LangName> </BudgetLangXML> <BudgetItemXML> <SERV_ServiceName>Publishing</SERV_ServiceName> <CAT_CategoryName>DTP</CAT_CategoryName> <BIT_ItemName>test 4 </BIT_ItemName> <PC_PriceCodeName>PubDTPPage</PC_PriceCodeName> <UNI_Name>Page </UNI_Name> <LANGS_Name>English</LANGS_Name> <LangName>Swedish</LangName> <BIT_ItemNbSell>2</BIT_ItemNbSell> <PLD_Price>8</PLD_Price> <Total>16</Total> <BIT_ItemID>4</BIT_ItemID> </BudgetItemXML> <BudgetItemXML> <SERV_ServiceName>Translation</SERV_ServiceName> <CAT_CategoryName>Doc translation</CAT_CategoryName> <BIT_ItemName>test 3 </BIT_ItemName> <PC_PriceCodeName>XltDocWord</PC_PriceCodeName> <UNI_Name>Word </UNI_Name> <LANGS_Name>Arabic</LANGS_Name> <LangName>English (UK)</LangName> <BIT_ItemNbSell>0</BIT_ItemNbSell> <PLD_Price>0.07</PLD_Price> <Total>0</Total> <BIT_ItemID>3</BIT_ItemID> </BudgetItemXML> <BudgetItemXML> <SERV_ServiceName>Translation</SERV_ServiceName> <CAT_CategoryName>Doc translation</CAT_CategoryName> <BIT_ItemName>test 3 </BIT_ItemName> <PC_PriceCodeName>XltDocWord</PC_PriceCodeName> <UNI_Name>Word </UNI_Name> <LANGS_Name>Danish</LANGS_Name> <LangName>Norwegian</LangName> <BIT_ItemNbSell>0</BIT_ItemNbSell> <PLD_Price>0.16</PLD_Price> <Total>0</Total> <BIT_ItemID>3</BIT_ItemID> </BudgetItemXML> <BudgetItemXML> <SERV_ServiceName>Translation</SERV_ServiceName> <CAT_CategoryName>Doc translation</CAT_CategoryName> <BIT_ItemName>test 3 </BIT_ItemName> <PC_PriceCodeName>XltDocWord</PC_PriceCodeName> <UNI_Name>Word </UNI_Name> <LANGS_Name>English</LANGS_Name> <LangName>Swedish</LangName> <BIT_ItemNbSell>4</BIT_ItemNbSell> <PLD_Price>0.15</PLD_Price> <Total>0.6</Total> <BIT_ItemID>3</BIT_ItemID> </BudgetItemXML> <BudgetItemXML> <SERV_ServiceName>Translation</SERV_ServiceName> <CAT_CategoryName>Other translation</CAT_CategoryName> <BIT_ItemName>test 2 </BIT_ItemName> <PC_PriceCodeName>XltTranslatorHour</PC_PriceCodeName> <UNI_Name>Hour </UNI_Name> <LANGS_Name>Arabic</LANGS_Name> <LangName>English (UK)</LangName> <BIT_ItemNbSell>50</BIT_ItemNbSell> <PLD_Price>14</PLD_Price> <Total>700</Total> <BIT_ItemID>2</BIT_ItemID> </BudgetItemXML> <BudgetItemXML> <SERV_ServiceName>Translation</SERV_ServiceName> <CAT_CategoryName>Other translation</CAT_CategoryName> <BIT_ItemName>test 2 </BIT_ItemName> <PC_PriceCodeName>XltTranslatorHour</PC_PriceCodeName> <UNI_Name>Hour </UNI_Name> <LANGS_Name>Danish</LANGS_Name> <LangName>Norwegian</LangName> <BIT_ItemNbSell>0</BIT_ItemNbSell> <PLD_Price>37</PLD_Price> <Total>0</Total> <BIT_ItemID>2</BIT_ItemID> </BudgetItemXML> <BudgetItemXML> <SERV_ServiceName>Translation</SERV_ServiceName> <CAT_CategoryName>Other translation</CAT_CategoryName> <BIT_ItemName>test 2 </BIT_ItemName> <PC_PriceCodeName>XltTranslatorHour</PC_PriceCodeName> <UNI_Name>Hour </UNI_Name> <LANGS_Name>English</LANGS_Name> <LangName>Swedish</LangName> <BIT_ItemNbSell>0</BIT_ItemNbSell> <PLD_Price>50</PLD_Price> <Total>0</Total> <BIT_ItemID>2</BIT_ItemID> </BudgetItemXML> <BudgetItemXML> <SERV_ServiceName>Translation</SERV_ServiceName> <CAT_CategoryName>Software translation</CAT_CategoryName> <BIT_ItemName>test 1 </BIT_ItemName> <PC_PriceCodeName>XltSoftwareWord</PC_PriceCodeName> <UNI_Name>Word </UNI_Name> <LANGS_Name>Arabic</LANGS_Name> <LangName>English (UK)</LangName> <BIT_ItemNbSell>10</BIT_ItemNbSell> <PLD_Price>0.09</PLD_Price> <Total>0.9</Total> <BIT_ItemID>1</BIT_ItemID> </BudgetItemXML> <BudgetItemXML> <SERV_ServiceName>Translation</SERV_ServiceName> <CAT_CategoryName>Software translation</CAT_CategoryName> <BIT_ItemName>test 1 </BIT_ItemName> <PC_PriceCodeName>XltSoftwareWord</PC_PriceCodeName> <UNI_Name>Word </UNI_Name> <LANGS_Name>Danish</LANGS_Name> <LangName>Norwegian</LangName> <BIT_ItemNbSell>15</BIT_ItemNbSell> <PLD_Price>0.18</PLD_Price> <Total>2.7</Total> <BIT_ItemID>1</BIT_ItemID> </BudgetItemXML> <BudgetItemXML> <SERV_ServiceName>Translation</SERV_ServiceName> <CAT_CategoryName>Software translation</CAT_CategoryName> <BIT_ItemName>test 1 </BIT_ItemName> <PC_PriceCodeName>XltSoftwareWord</PC_PriceCodeName> <UNI_Name>Word </UNI_Name> <LANGS_Name>English</LANGS_Name> <LangName>Swedish</LangName> <BIT_ItemNbSell>0</BIT_ItemNbSell> <PLD_Price>0.18</PLD_Price> <Total>0</Total> <BIT_ItemID>1</BIT_ItemID> </BudgetItemXML> <BudgetItemXML> <SERV_ServiceName>Translation</SERV_ServiceName> <CAT_CategoryName>Software translation</CAT_CategoryName> <BIT_ItemName>test 5 </BIT_ItemName> <PC_PriceCodeName>XltSoftwareWord</PC_PriceCodeName> <UNI_Name>Word </UNI_Name> <LANGS_Name>Arabic</LANGS_Name> <LangName>English (UK)</LangName> <BIT_ItemNbSell>3</BIT_ItemNbSell> <PLD_Price>0.09</PLD_Price> <Total>0.27</Total> <BIT_ItemID>5</BIT_ItemID> </BudgetItemXML> <BudgetItemXML> <SERV_ServiceName>Translation</SERV_ServiceName> <CAT_CategoryName>Software translation</CAT_CategoryName> <BIT_ItemName>test 5 </BIT_ItemName> <PC_PriceCodeName>XltSoftwareWord</PC_PriceCodeName> <UNI_Name>Word </UNI_Name> <LANGS_Name>Danish</LANGS_Name> <LangName>Norwegian</LangName> <BIT_ItemNbSell>1</BIT_ItemNbSell> <PLD_Price>0.18</PLD_Price> <Total>0.18</Total> <BIT_ItemID>5</BIT_ItemID> </BudgetItemXML> <BudgetItemXML> <SERV_ServiceName>Translation</SERV_ServiceName> <CAT_CategoryName>Software translation</CAT_CategoryName> <BIT_ItemName>test 5 </BIT_ItemName> <PC_PriceCodeName>XltSoftwareWord</PC_PriceCodeName> <UNI_Name>Word </UNI_Name> <LANGS_Name>English</LANGS_Name> <LangName>Swedish</LangName> <BIT_ItemNbSell>0</BIT_ItemNbSell> <PLD_Price>0.18</PLD_Price> <Total>0</Total> <BIT_ItemID>5</BIT_ItemID> </BudgetItemXML> </dsBudget> XSL FILE : ------------------------------------------------------------------------------------------------------------ <!-- File: temp.xsl Author: Elise Dupont 07/02/2002 Desc: Transform xml into quote where catagorisation is choosable --> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="urn:schemas-microsoft-com:xml-data"> <xsl:output method="html" indent="yes"/> <xsl:key name="item-by-id" match="BudgetItemXML" use="BIT_ItemID" /> <xsl:key name="item-by-cat" match="BudgetItemXML" use="CAT_CategoryName" /> <xsl:key name="item-by-service" match="BudgetItemXML" use="SERV_ServiceName" /> <xsl:key name="item-by-service-id" match="BudgetItemXML" use=" concat(SERV_ServiceName, ' ',BIT_ItemID)" /> <xsl:key name="item-by-id-service" match="BudgetItemXML" use="concat(BIT_ItemID, ' ',SERV_ServiceName)" /> <xsl:key name="item-by-service-cat" match="BudgetItemXML" use=" concat(SERV_ServiceName, ' ', CAT_CategoryName)" /> <xsl:key name="item-by-id-service-cat" match="BudgetItemXML" use=" concat(BIT_ItemID, ' ', SERV_ServiceName,' ',CAT_CategoryName)" /> <xsl:key name="item-by-service-id-cat" match="BudgetItemXML" use=" concat(SERV_ServiceName,' ',BIT_ItemID, ' ', CAT_CategoryName)" /> <xsl:key name="item-by-service-cat-id" match="BudgetItemXML" use=" concat(SERV_ServiceName, ' ', CAT_CategoryName,' ',BIT_ItemID)" /> <!-- Grouping by : Task (SERV_ServiceName) then Activity (CAT_CategoryName) --> <xsl:template match="dsBudget"> <html> <head> <title>Untitled</title> </head> <body> <table cellspacing="0"> <tr> <td> <IMG height="45" src="D:\backup\My Documents Boulot\devp\Quotation\XML transformation\logo.jpg" width="150" border="0"/> </td> <td> <table cellspacing="0"> <TR> <td bgcolor="#000080" height="45"> <table style="color: White;" cellspacing="0"> <tr> <td width="100" >Client: </td> <td width="100" style="FONT-WEIGHT: bold "><xsl:value-of select="/*/*[1]/*[6]" /></td> <td width="100" >Quotation #: </td> <td width="100" style="FONT-WEIGHT: bold "><xsl:value-of select="/*/*[1]/*[1]" /></td> <td width="100">Date: </td> <td width="100" style="FONT-WEIGHT: bold "><xsl:value-of select="/*/*[1]/*[5]" /></td> </tr> <tr> <td>Project: </td> <td style="FONT-WEIGHT: bold"></td> <td>Project Code: </td> <td style="FONT-WEIGHT: bold">< xsl:value-of select="/*/*[1]/*[7]" /></td> <td>Author: </td> <td style="FONT-WEIGHT: bold">< xsl:value-of select="/*/*[1]/*[4]" /></td> </tr> </table> </td> </TR> </table> </td> </tr> </table> Quote Done in <xsl:value-of select="/*/*[1]/*[3]" /> <TABLE border="0" cellspacing="0"> <TR bgcolor="#000080" style="color: White;" border="1"> <TD width="100" border="1"><table style="color: White;"><tr> <td>Task</td> <td><input type="Button" name="swap_right" value='>'/></td> </tr></table></TD> <TD width="100" border="1"><table style="color: White;"><tr> <td><input type="Button" name="swap_left" value='<'/></td> <td>Activity</td> </tr></table></TD> <TD width="100" border="1">Quote Item</TD> <TD width="100" border="1">PriceCode</TD> <TD width="50" border="1">Unit</TD> <xsl:for-each select="BudgetLangXML"> <td > <TABLE border="1" cellspacing="0" > <TR bgcolor="#000080" style="color: White;"> <TD width="150" colspan="3"><xsl:value-of select=" LANGS_Name" /> / <xsl:value-of select="LangName" /></TD> </TR> <TR bgcolor="#000080" style="color: White;"> <TD width="50" >Qty</TD> <TD width="50" >Unit Price</TD> <TD width="50" >Total</TD> </TR> </TABLE> </td> </xsl:for-each> <TD width="100" border="1">Total Lang</TD> </TR> <xsl:for-each select="BudgetItemXML[count(. | key('item-by-service', SERV_ServiceName)[1]) = 1]"> <TR> <TD width="50" colspan="3"><xsl:value-of select=" SERV_ServiceName" /></TD> </TR> <xsl:variable name="service_items" select="key ('item-by-service', SERV_ServiceName)" /> <xsl:for-each select="$service_items[generate-id() =generate-id(key('item-by-service-cat',concat(SERV_ServiceName, ' ', CAT_CategoryName))[1])]"> <TR> <TD width="100" bgcolor="#E5E5E5"></TD> <TD width="200" colspan="3">< xsl:value-of select="CAT_CategoryName" /></TD> </TR> <xsl:variable name="id_items" select="key ('item-by-cat', CAT_CategoryName)" /> <xsl:for-each select="$id_items[generate-id() =generate-id(key('item-by-service-cat-id',concat(SERV_ServiceName, ' ', CAT_CategoryName,' ',BIT_ItemID))[1])]"> <TR> <TD width="100" bgcolor="#E5E5E5"></TD> <TD width="100" bgcolor="#E5E5E5"></TD> <TD width="150" ><xsl:value-of select=" BIT_ItemName" /> </TD> <TD width="100"><xsl:value-of select=" PC_PriceCodeName" /></TD> <TD width="50"><xsl:value-of select=" UNI_Name" /> </TD> <xsl:for-each select=" $service_items[generate-id() =generate-id(key ('item-by-service-cat',concat(SERV_ServiceName, ' ', CAT_CategoryName))[1])]"> <td> <table cellspacing="0"> <td width="50" align=" center"><xsl:value-of select="BIT_ItemNbSell" /></td> <td width="50" align=" center"><xsl:value-of select="PLD_Price" /></td> <td width="50" align=" right"><xsl:value-of select="Total" /></td> </table> </td> </xsl:for-each> <!-- need help here Total for the line of the item this means for the given BIT_ItemID sum all the BudgetItemXML/Total value example : select the node where BIT_ItemID = 3 --> <TD width="100" align="right" style=" FONT-WEIGHT: bold"><xsl:value-of select="sum(Total)" /> </TD> </TR> </xsl:for-each> <TR> <TD width="100" bgcolor="#E5E5E5"></TD> <TD width="100" bgcolor="#E5E5E5"></TD> <TD width="200" colspan="3" style=" FONT-WEIGHT: bold">Subtotal <xsl:value-of select="CAT_CategoryName" /></TD> <xsl:for-each select=" $service_items[generate-id() =generate-id(key ('item-by-service-cat',concat(SERV_ServiceName, ' ', CAT_CategoryName))[1])]"> <td> <table cellspacing="0"> <td width="50" align="center">-</td> <td width="50" align="center">-</td> <!-- need help here Total for the category this means for the given SERV_ServiceName and CAT_CategoryName sum all the BudgetItemXML/Total value example : sum(BudgetLangXML/the good Section & the good category/ Total)--> <td width="50" align="right" style="FONT-WEIGHT: bold" ><xsl:value-of select="sum(Total)"/></td > </table> </td> </xsl:for-each> </TR> </xsl:for-each> <TR> <TD width="200" style="FONT-WEIGHT: bold " colspan="3">Total <xsl:value-of select="SERV_ServiceName" /></TD> <TD width="100">-</TD> <TD width="50">-</TD> <xsl:for-each select=" $service_items[generate-id() =generate-id(key ('item-by-service-cat',concat(SERV_ServiceName, ' ', CAT_CategoryName))[1])]"> <td> <table cellspacing="0"> <td width="50" align=" center">-</td> <td width="50" align=" center">-</td> <td width="50" align=" right" style="FONT-WEIGHT: bold"><xsl:value-of select="Total" /></td> </table> </td> </xsl:for-each> <!-- need help here Total for the line of the Task section this means for the given Task sum all the BudgetItemXML/Total value example : make the totalon SERV_ServiceName = Translation --> <TD width="100" align="right" style=" FONT-WEIGHT: bold"><xsl:value-of select="sum(Total)" /> </TD> </TR> </xsl:for-each> </TABLE> </body> </html> </xsl:template> </xsl:stylesheet> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] fo:inline vs. fo:wrapper, David Tolpin | Thread | Re: [xsl] need help for sum() and p, Joerg Heinicke |
RE: [xsl] node-set from a string?, Michael Kay | Date | Re: [xsl] Extension Function to pro, Joerg Heinicke |
Month |