| | |
Need help (urgent)
Please support our XML, XSLT and XPATH advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2008
Posts: 22
Reputation:
Solved Threads: 0
Hi,
May be following code can help you....
here i assume that, there are only 3 <CD> under the <CDs> tag...
OUTPUT will looks like
Cheers,
Mahesh
May be following code can help you....
here i assume that, there are only 3 <CD> under the <CDs> tag...
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html"/> <xsl:template match="Specials"> <html> <head> <title><xsl:apply-templates select="./Title"/></title> </head> <body> <xsl:apply-templates /> </body> </html> </xsl:template> <xsl:template match="Specials/Title" /> <xsl:template match="//Message" /> <xsl:template match="//CDs"> <xsl:variable name="t1" select="./CD[1]//PriceUK" /> <xsl:variable name="t2" select="./CD[2]//PriceUK" /> <xsl:variable name="t3" select="./CD[3]//PriceUK" /> <xsl:for-each select="./CD"> <div> <p>Title: <xsl:value-of select="@title" /></p> <p>Artist: <xsl:value-of select="./Artist" /></p> <p>Total Tracks: <xsl:value-of select="count(./Tracks/Track)" /></p> <xsl:for-each select="./Tracks/Track"> <ul> <li>Track: <xsl:value-of select="." /></li> <li>Track Length: <xsl:value-of select="@length" /></li> </ul> </xsl:for-each> </div><hr /> </xsl:for-each> <p>If customer select only first CD then, Price in UK: <xsl:value-of select="$t1" /></p> <p>If customer select only Second CD then, Price in UK: <xsl:value-of select="$t2" /></p> <p>If customer select only Third CD then, Price in UK: <xsl:value-of select="$t3" /></p> <hr /> <p>If customer select First and Second CD then, Price in UK: <xsl:value-of select="$t1 + $t2" /></p> <p>If customer select First and Third CD then, Price in UK: <xsl:value-of select="$t1 + $t3" /></p> <p>If customer select Second and Third CD then, Price in UK: <xsl:value-of select="$t2 + $t3" /></p> <p>If customer select All CDs then, Price in UK: <xsl:value-of select="$t1 + $t2 + $t3" /></p> </xsl:template> </xsl:stylesheet>
OUTPUT will looks like
<html> <head> <title></title> </head> <body> <div> <p>Title: Kind of Blue</p> <p>Artist: Miles Davis</p> <p>Total Tracks: 5</p> <ul> <li>Track: So What</li> <li>Track Length: 9:22</li> </ul> <ul> <li>Track: Frddie Freeloader</li> <li>Track Length: 9:46</li> </ul> <ul> <li>Track: Blue in Green</li> <li>Track Length: 5:37</li> </ul> <ul> <li>Track: All Blues</li> <li>Track Length: 11:33</li> </ul> <ul> <li>Track: Flamenco Sketches</li> <li>Track Length: 9:26</li> </ul> </div><hr> <div> <p>Title: Cookin</p> <p>Artist: Miles Davis</p> <p>Total Tracks: 4</p> <ul> <li>Track: My Funny Valentine</li> <li>Track Length: 5:57</li> </ul> <ul> <li>Track: Blues by Five</li> <li>Track Length: 9:53</li> </ul> <ul> <li>Track: Airegin</li> <li>Track Length: 4:22</li> </ul> <ul> <li>Track: Tune-Up</li> <li>Track Length: 13:03</li> </ul> </div><hr> <div> <p>Title: Blue Train</p> <p>Artist: John Coltrane</p> <p>Total Tracks: 5</p> <ul> <li>Track: Blue Train</li> <li>Track Length: 10:39</li> </ul> <ul> <li>Track: Moment's Notice</li> <li>Track Length: 9:06</li> </ul> <ul> <li>Track: Locomotion</li> <li>Track Length: 7:11</li> </ul> <ul> <li>Track: I'm Old Fashioned</li> <li>Track Length: 7:55</li> </ul> <ul> <li>Track: Lazy Bird</li> <li>Track Length: 7:03</li> </ul> </div><hr> <p>If customer select only first CD then, Price in UK: 8.39</p> <p>If customer select only Second CD then, Price in UK: 5.59</p> <p>If customer select only Third CD then, Price in UK: 6.29</p> <hr> <p>If customer select First and Second CD then, Price in UK: 13.98</p> <p>If customer select First and Third CD then, Price in UK: 14.68</p> <p>If customer select Second and Third CD then, Price in UK: 11.879999999999999</p> <p>If customer select All CDs then, Price in UK: 20.27</p> </body> </html>
Cheers,
Mahesh
Last edited by mlohokare; Mar 30th, 2009 at 4:55 am.
•
•
Join Date: Apr 2009
Posts: 46
Reputation:
Solved Threads: 2
from sample
looking for Total duration
<xsl:value-of select="count(/Specials/CDs/CD[@title='Kind of Blue']/Tracks/Track[.='All Blues']/preceding-sibling::Track)+1"/>
<xsl:value-of select="/Specials/CDs/CD[@title='Cookin']/Tracks/Track[2]"/>
<xsl:value-of select="sum(/Specials/CDs//CD/PriceUK)"/>
Hemlut Hagemann
looking for Total duration
XML, XSLT and XPATH Syntax (Toggle Plain Text)
<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" indent="yes"/> <xsl:key name="sum" match="//@length" use="number(translate(.,':','.'))"/> <xsl:template match="/"> <xsl:apply-templates select="Specials"/> </xsl:template> <xsl:template match="Specials"> <html> <head> <title> <xsl:apply-templates select="Title"/> </title> </head> <body> <xsl:apply-templates select="CDs"/> <xsl:call-template name="question789"/> </body> </html> </xsl:template> <xsl:template match="CDs"> <xsl:apply-templates select="CD"/> </xsl:template> <xsl:template match="CD"> <div> <p>Title: <xsl:value-of select="@title"/></p> <p>Artist: <xsl:value-of select="./Artist"/></p> <p>Total Tracks: <xsl:value-of select="count(./Tracks/Track)"/></p> <xsl:apply-templates select="Tracks"/> </div> </xsl:template> <xsl:template match="Tracks"> <xsl:apply-templates select="Track"/> <p> <xsl:call-template name="timesum"> <xsl:with-param name="km" select="child::Track/@length"/> </xsl:call-template> </p> </xsl:template> <xsl:template match="Track"> <ul> <li>Track: <xsl:value-of select="."/></li> <li>Track Length: <xsl:value-of select="@length"/></li> </ul> </xsl:template> <xsl:template name="timesum"> <xsl:param name="km"/> <xsl:param name="ak" select="1"/> <xsl:param name="min" select="0"/> <xsl:param name="hour" select="0"/> <xsl:variable name="c" select="count($km)"/> <xsl:choose> <xsl:when test="$ak <= $c"> <xsl:variable name="tmin" select="substring-after($km[$ak],':')"/> <xsl:variable name="thour" select="substring-before($km[$ak],':')"/> <xsl:call-template name="timesum"> <xsl:with-param name="ak" select="$ak+1"/> <xsl:with-param name="km" select="$km"/> <xsl:with-param name="hour" select="$hour + $thour"/> <xsl:with-param name="min" select="$min + $tmin"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="concat('Total duration',$hour+($min -$min mod 60) div 60,':',format-number($min mod 60,'00'))"/> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template name="question789"> <h1>answer of question 7,8,9</h1> <p>Track number of ‘All Blues’ song on ‘Kind of Blue’ CD</p> <p>count(/Specials/CDs/CD[@title='Kind of Blue']/Tracks/Track[.='All Blues']/preceding-sibling::Track)+1</p> <h3> <xsl:value-of select="count(/Specials/CDs/CD[@title='Kind of Blue']/Tracks/Track[.='All Blues']/preceding-sibling::Track)+1"/> </h3> <p>Name of second track on ‘Cookin’ CD</p> <p>/Specials/CDs/CD[@title='Cookin']/Tracks/Track[2]</p> <h3> <xsl:value-of select="/Specials/CDs/CD[@title='Cookin']/Tracks/Track[2]"/> </h3> <p>Total cost to purchase all 3 CDs (UK prices)</p> <p>sum(/Specials/CDs//CD/PriceUK)</p> <h3> <xsl:value-of select="sum(/Specials/CDs//CD/PriceUK)"/> </h3> </xsl:template> </xsl:stylesheet>
<xsl:value-of select="count(/Specials/CDs/CD[@title='Kind of Blue']/Tracks/Track[.='All Blues']/preceding-sibling::Track)+1"/>
<xsl:value-of select="/Specials/CDs/CD[@title='Cookin']/Tracks/Track[2]"/>
<xsl:value-of select="sum(/Specials/CDs//CD/PriceUK)"/>
Hemlut Hagemann
![]() |
Similar Threads
- pls heeeeeeeeelp its urgent. (C)
- Urgent! (C++)
- URGENT: Need help on I/O code! (Java)
- Urgent help (Networking Hardware Configuration)
- Homepage keeps switching back to a porn site (Web Browsers)
- Importing SQL Script File - Urgent !! (Database Design)
Other Threads in the XML, XSLT and XPATH Forum
- Previous Thread: help with xsl for avg - ASAP
- Next Thread: XML pagination
Views: 578 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for XML, XSLT and XPATH
api blogger blogging code dataset delete development dynamiccreationofnvariablesinxslt error firstthreecharacterofastringrequired flipbook gdata google html include java link linspire linux microsoft news node openoffice overwrite precedence programming rss serialization standards swf template transform variable w3c web xml xmlnotloading xmlonserver xsl xslt





