[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: getAttribute()
Here is a complete stylesheet i wrote as an example of XML/XSL technologies for my web site (http://www.cabinfo.com i'm sorry, but the web site is in french, i haven't time to translate it now !) In this stylesheet i extract many attribut from the elements <INGREDIENT> and <RECETTE> there is also a script which can be interessant as it iterate through all the childrens elements of the RECETTE element. <xsl> <define-script><![CDATA[ function GetCalorie(thisRecette) { // Cette fonction renvoie le nombre de calorie par parts // This function return the total amount of "calories" for one portion // Notice that the script is not optimized, cause it's just an example // It **need** to be optimized !!! var CalorieParPart, aCal, ingredients, numIngredients, Ingredient; var TotalCalorie; TotalCalorie = 0; ingredients = thisRecette.children.item("INGREDIENTS", 0); numIngredients = ingredients.children.item("INGREDIENT").length; for (i = 0; i < numIngredients; i++) { Ingredient = ingredients.children.item("INGREDIENT", i); aCal = Ingredient.getAttribute("CALORIE"); TotalCalorie = TotalCalorie + parseInt(aCal, 10); } CalorieParPart = TotalCalorie / parseInt(thisRecette.getAttribute("NOMBREPARTS"), 10); return CalorieParPart; } ]]></define-script> <rule> <root/> <DIV font="10pt Arial"> <children/> </DIV> </rule> <rule> <target-element type="RECETTE"/> <TABLE BORDER="1"> <TR> <TD COLSPAN="5" font="14pt" color="red" font-weight="bold"><eval>getAttribute("TITRE")</eval> </TD> </TR> <TR> <TD COLSPAN="5"> <select-elements> <target-element type="DESCRIPTION"/> </select-elements> </TD> </TR> <TR> <!-- This rule may interest you for your problem --> <TD width="100px" font="10pt"><eval>getAttribute("NOMBREPARTS")</eval> portions </TD> <!-- This rule may interest you for your problem --> <TD width="100px" font="10pt">Diff. : <eval>getAttribute("DIFFICULTE")</eval> </TD> <!-- This rule may interest you for your problem --> <TD font="10pt">Cuisson : <eval>getAttribute("TEMPSCUISSON")</eval> min. </TD> <!-- This rule may interest you for your problem --> <TD font="10pt">Préparation : <eval>getAttribute("TEMPSPREPA")</eval> min. </TD> <!-- This rule may interest you for your problem --> <TD font="10pt">Calories : <eval>formatNumber(GetCalorie(this), "1")</eval> </TD> </TR> <TR> <TD VALIGN="TOP" COLSPAN="2" ROWSPAN="2" font="10pt"> <select-elements> <target-element type="INGREDIENTS"/> </select-elements> </TD> <TD COLSPAN="3" font="10pt"> <select-elements> <target-element type="OPERATIONS"/> </select-elements> </TD> </TR> <TR> <TD COLSPAN="3"> <select-elements> <target-element type="CONSEIL"/> </select-elements> </TD> </TR> <TR> <TD COLSPAN="5" ALIGN="CENTER"> <select-elements> <target-element type="PHOTO"/> </select-elements> </TD> </TR> </TABLE> <BR/> <HR SIZE="1" WIDTH="60%" ALIGN="CENTER"/> <BR page-break-after="always"/> <DIV page-break-after="always"></DIV> </rule> <rule> <target-element type="DESCRIPTION"/> <SPAN font="10pt Times" font-weight="bold" font-style="italic" color="black"> <children/> </SPAN> </rule> <rule> <target-element type="CONSEIL"/> <DIV color="red" font="10pt" font-weight="bold">Mon secret : </DIV> <DIV color="black" font="10pt" font-style="italic"> <children/> </DIV> </rule> <rule> <target-element type="OPE"/> <LI/><children/> </rule> <!-- This rule may interest you for your problem --> <rule> <target-element type="INGREDIENT"/> <LI/><eval>getAttribute("QTE")</eval> <eval>getAttribute("UNITE")</eval> <eval>getAttribute("NOM")</eval> </rule> <rule> <target-element type="OPERATIONS"/> <UL margin="20px"><children/></UL> </rule> <rule> <target-element type="INGREDIENTS"/> <UL margin="20px"><children/></UL> </rule> <rule> <target-element type="PHOTO"/> <IMG src='=getAttribute("URL")' alt="image non disponible"/> </rule> </xsl> I hope this help you. You can see this example online at : http://www.cabinfo.com/cookml.htm Best Regards. Alain From France. Frank Boumphrey wrote: > > I tried much of this evening trying to get the second attribute to work, and > I couldn't. I'd never tried with two atributes before. Perhaps Johnathan > Marsh can enlighten us? > > Frank > -----Original Message----- > From: Henning Behme <hb@xxxxxxxxxxx> > To: XSL-List@xxxxxxxxxxxxxxxx <XSL-List@xxxxxxxxxxxxxxxx> > Date: Sunday, April 05, 1998 10:22 AM > Subject: getAttribute() > > >Hi, > > > >I am trying to create different views on a document containing a web > >timeline, which I use for an upcoming article on XSL in our magazine > >(see sig). The structure of events is really simple, something like the > >following: > > > ><year which="1998"> > > > ><event cat="special" status="dayoff"> > > <day>1</day> > > <month>1</month> > > <what>NewYear</what> > ></event> > > > ><!-- more events --> > ></year> > > > >Is it possible that you can't get hold of the second attribute using > >msxsl? The first attribute (of one, admittedly) gets out fine via style > >sheet, it is only the second one that the MS processor doesn't seem to > >like particularly :-( > > > >The error message looks like: > > > >Script error: line = 1, col = 0 (line is offset from the SCRIPT tag) > >Error returned from property or method call > > > >The two parts of the style sheet are the following: > > > >a) in element "event" (this one works) > > <eval>ancestor("year", this).getAttribute("which")</eval> > > > > > >b) in element "what" (this one doesn't) > > <eval>ancestor("event", this).getAttribute("status")</eval> > > > > > > > >Has anyone experienced anything similar? > > > >Best regards, > >Henning Behme > > > >iX - Magazin fuer professionelle Informationstechnik > >Helstorfer Str. 7 * 30625 Hannover * Germany > >http://www.heise.de/ix/ * +49 511 5352-374 * -361 (Fax) > >------ White, adj. and n. Black (Ambrose Bierce) ------ > > > > > > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list 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
|