|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
XML/XSL problem again
Hi again!
This message is corresponding to the "XML/XSL problem" posted. Can anybody explain to me which is the difference from the next two codes ? (because with the first I obtain the results what I want but in the second when I use another template I didn't obtain the necessary reslts) First code: <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body><h2>Report</h2> <table border="1"> <caption valign="top">FRANCE</caption> <tr bgcolor="#9acd32"> <th>Client</th> <th>Agence</th> <th>Proposition</th> <th>PropositionM</th> <th>Code</th> </tr> <xsl:for-each select="dataa/propo"> <tr> <td><xsl:value-of select="client"/></td> <td><xsl:value-of select="agence"/></td> <td><xsl:value-of select="proposition"/></td> <td><xsl:value-of select="propositionM"/></td> <td><xsl:value-of select="code"/></td> </tr> </xsl:for-each> </table> </body></html> </xsl:template> </xsl:stylesheet> Second code: <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html><body><h2>Report</h2> <table border="1"> <caption valign="top">FRANCE</caption> <xsl:apply-templates select="//propo"/> </table></body> </html> </xsl:template> <xsl:template match="propo"> <xsl:for-each select="dataa/propo"> <tr> <td><xsl:value-of select="client"/></td> <td><xsl:value-of select="agence"/></td> <td><xsl:value-of select="proposition"/></td> <td><xsl:value-of select="propositionM"/></td> <td><xsl:value-of select="code"/></td> </tr> </xsl:for-each> </xsl:template> </xsl:stylesheet> Thanks in advanced, Mitch. |
|
#2
|
||||
|
||||
|
well....in the first template, the for-each loop searches for "dataa/propo" nodes under the root node "/".
In the second template the loop is looking for "dataa/propo" nodes under each "propo" node. In this one the "<xsl:apply-templates select="//propo"/>" tag is already doing what the for-each loop is intended to do, because it applies a template to every "propo" node, so you can remove the loop. hope i've explained myself clearly ![]() Last edited by tank80 : August 1st, 2003 at 02:24 AM. |
|
#3
|
|||
|
|||
|
Thanks a lot tank80...
If you have time maybe you can help me and with the other "XML/XSL problem"(there I pushed and a xml code). I made a template like this: <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl utput method="html" media-type="text/html; charset=ISO-8859-1"/><xsl:template match="/"> <html><body> <table border="1"> <caption valign="top">FRANCE</caption> <tr bgcolor="#9acd32"> <th>Client</th> <th>Agence</th> <th>Proposition</th> <th>PropositionM</th> <th>Code</th> </tr> <h4>Vous avez</h4> <xsl:apply-templates select="//dataa"/> </body> </html> </xsl:template> <xsl:template match="dataa"> <xsl:for-each select="propo"> <xsl:sort select="propositionM" order="ascending"/> <xsl:sort select="code" order="ascending"/> <xsl:if test='client="Ana"'> <xsl:if test='proposition="good"'> <tr> <td><xsl:value-of select="client"/></td> <td><xsl:value-of select="agence"/></td> <td><xsl:value-of select="proposition"/></td> <td><xsl:value-of select="propositionM"/></td> <td><xsl:value-of select="code"/></td> </tr> </xsl:if> </xsl:if> </xsl:for-each> </table> <!-- Now I want to show my SUM(..) I tried like this: - I declared a variable <xsl:variable name="total" select="sum(propo[client="Ana"][proposition="good"]/price)"/> <B>Total Sum</B>: <xsl:value-of select="$total"/> but it didn't worked --> </xsl:template> So, I ordered for client "Ana" and proposition "good" by propositionM and code; now I want to show SUM(price) for the selected items. Can you (or anybody) tell me how should I do ? Thanks again, Mitch. |
|
#4
|
|||
|
|||
|
Thanks a lot tank80...
If you have time maybe you can help me and with the other "XML/XSL problem"(there I pushed and a xml code). My source code: <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl utput method="html" media-type="text/html; charset=ISO-8859-1"/><xsl:template match="/"> <html><body> <table border="1"> <caption valign="top">FRANCE</caption> <tr bgcolor="#9acd32"> <th>Client</th> <th>Agence</th> <th>Proposition</th> <th>PropositionM</th> <th>Code</th> </tr> <h4>Vous avez</h4> <xsl:apply-templates select="//dataa"/> </body> </html> </xsl:template> <xsl:template match="dataa"> <xsl:for-each select="propo"> <xsl:sort select="propositionM" order="ascending"/> <xsl:sort select="code" order="ascending"/> <xsl:if test='client="Ana"'> <xsl:if test='proposition="good"'> <tr> <td><xsl:value-of select="client"/></td> <td><xsl:value-of select="agence"/></td> <td><xsl:value-of select="proposition"/></td> <td><xsl:value-of select="propositionM"/></td> <td><xsl:value-of select="code"/></td> </tr> </xsl:if> </xsl:if> </xsl:for-each> </table> <!-- Now I want to show my SUM(..) I tried like this: - I declared a variable <xsl:variable name="total" select="sum(propo[client="Ana"][proposition="good"]/price)"/> <B>Total Sum</B>: <xsl:value-of select="$total"/> but it didn't worked --> </xsl:template> So, I ordered for client "Ana" and proposition "good" by propositionM and code; now I want to show SUM(price) for the selected items. Can you (or anybody) tell me how should I do ? Thanks again, Mitch. |
|
#5
|
||||
|
||||
|
let's try it...
first, check the quotes: you have this Code:
<xsl:variable name="total" select="sum(propo[client="Ana"][proposition="good"]/price)"/> <B>Total Sum</B>: <xsl:value-of select="$total"/> double quotes in the select attribute text are closing the attribute's quotes, so change it like this: Code:
<xsl:variable name="total" select="sum(propo[client='Ana'][proposition='good']/price)"/> <B>Total Sum</B>: <xsl:value-of select="$total"/> also, as a general advice, always enclose attributes between double quotes " " and use single quotes in the text ' ' Last edited by tank80 : August 1st, 2003 at 04:39 AM. |
|
#6
|
|||
|
|||
|
Thanks for your advice.
Now the code is working. <xsl:template match="dataa"> <xsl:for-each select="propo"> <xsl:sort select="propositionM" order="ascending"/> <xsl:sort select="code" order="ascending"/> <xsl:if test='client="Ana"'> <xsl:if test='proposition="good"'> <tr> <td><xsl:value-of select="client"/></td> <td><xsl:value-of select="agence"/></td> <td><xsl:value-of select="proposition"/></td> <td><xsl:value-of select="propositionM"/></td> <td><xsl:value-of select="code"/></td> </tr> </xsl:if> </xsl:if> </xsl:for-each> </table> <B>Total Sum: </B>: <xsl:value-of select="$total"/> </xsl:template> But now I have another problem: I want to write the informations grouped by propositionM(so I have many propositionM corresponding to "Ana" client and "good" proposition... I want to display the info like this: propositionM 1 goodAfternoon client/agence/intervention/price (corresponding for"goodAfternoon) propositionM 1 goodEvening client/agence/intervention/price (corresponding for"goodAfternoon) propositionM 1 goodMorning client/agence/intervention/price (corresponding for"goodAfternoon) Could you (or somebody else) to give me an idea to resolve this problem ? Thanks again, Mitch. |
|
#7
|
|||
|
|||
|
Sorry! I want to write these informations:
propositionM 1 goodAfternoon client/agence/intervention/price (corresponding for"goodAfternoon) propositionM 1 goodEvening client/agence/intervention/price (corresponding for"goodEvening) propositionM 1 goodMorning client/agence/intervention/price (corresponding for"goodMorning) Thanks! |
|
#8
|
|||
|
|||
|
Did you know how could I modify a variable in XML ?
Thanks, Mitch. |
|
#9
|
|||
|
|||
|
Sorry, guys!
I found that in XML I can't modify a variable. And I know I wasn't very clear. But I have this xml code: <?xml version="1.0" ?> <dataa> <propo> <client>Bambi</client> <agence>Big Teddy</agence> <proposition>badd</proposition> <propositionM>baddGuy</propositionM> <intervention>1</intervention> <activite>z</activite> <code>Mis1</code> <price>475</price> </propo> <propo> <client>Bambi</client> <agence>Big Teddy</agence> <proposition>badd</proposition> <propositionM>baddGuy</propositionM> <intervention>2</intervention> <activite>x</activite> <code>Mis2</code> <price>205</price> </propo> <propo> <client>Ana</client> <agence>Little Marie</agence> <proposition>good</proposition> <propositionM>goodAfternoon</propositionM> <intervention>1</intervention> <activite>a</activite> <code>Mis1</code> <price>200</price> </propo> <propo> <client>Ana</client> <agence>Little Marie</agence> <proposition>good</proposition> <propositionM>goodAfternoon</propositionM> <intervention>2</intervention> <activite>a</activite> <code>Mis2</code> <price>250</price> </propo> <propo> <client>Ana</client> <agence>Little Marie</agence> <proposition>good</proposition> <propositionM>goodAfternoon</propositionM> <intervention>3</intervention> <activite>d</activite> <code>Mis7</code> <price>350</price> </propo> <propo> <client>Ana</client> <agence>Little Marie</agence> <proposition>good</proposition> <propositionM>goodAfternoon</propositionM> <intervention>4</intervention> <activite>d</activite> <code>Mis2</code> <price>50</price> </propo> <propo> <client>Ana</client> <agence>Little Marie</agence> <proposition>good</proposition> <propositionM>goodMorning</propositionM> <intervention>1</intervention> <activite>a</activite> <code>Mis1</code> <price>350</price> </propo> <propo> <client>Ana</client> <agence>Little Marie</agence> <proposition>good</proposition> <propositionM>goodMorning</propositionM> <intervention>2</intervention> <activite>b</activite> <code>Mis2</code> <price>400</price> </propo> <propo> <client>Ana</client> <agence>Little Marie</agence> <proposition>good</proposition> <propositionM>goodMorning</propositionM> <intervention>3</intervention> <activite>b</activite> <code>Mis7</code> <price>250</price> </propo> <propo> <client>Ana</client> <agence>Little Marie</agence> <proposition>good</proposition> <propositionM>goodMorning</propositionM> <intervention>4</intervention> <activite>e</activite> <code>Mis1</code> <price>550</price> </propo> <propo> <client>Ana</client> <agence>Little Marie</agence> <proposition>good</proposition> <propositionM>goodEvening</propositionM> <intervention>1</intervention> <activite>b</activite> <code>Mis1</code> <price>250</price> </propo> <propo> <client>Ana</client> <agence>Little Marie</agence> <proposition>good</proposition> <propositionM>goodMorning</propositionM> <intervention>2</intervention> <activite>a</activite> <code>Mis2</code> <price>500</price> </propo> </dataa> Noe I want to group "intervention" per "code" for "Ana" client and "good" proposition. I want an html in which I'll have the information like this: <client>Ana</client> <proposition>good</proposition> <propositionM>goodAfternoon <intervention>1</intervention> <activite>a</activite> <code>Mis1</code> <price>100<price> <intervention>2</intervention> <activite>a</activite> <code>Mis2</code> <price>250<price> <intervention>3</intervention> <activite>d</activite> <code>Mis7</code> <price>350<price> <intervention>4</intervention> <activite>d</activite> <code>Mis2</code> <price>50<price> </propositionM> <propositionM>goodEvening</propositionM> ... ... ... Maybe now I am more clear... Could anybody help me with any idea for this problem ? Thanks in advanced, Mitch. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > XML/XSL problem again |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|