Need help (urgent)

Please support our XML, XSLT and XPATH advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Mar 2009
Posts: 7
Reputation: dollycharm is an unknown quantity at this point 
Solved Threads: 0
dollycharm dollycharm is offline Offline
Newbie Poster

Need help (urgent)

 
0
  #1
Mar 27th, 2009
7. Track number of ‘All Blues’ song on ‘Kind of Blue’ CD

8. Name of second track on ‘Cookin’ CD

9. Total cost to purchase all 3 CDs (UK prices)

Please see attached file for XML....

I need to have code for XSL..... I couldn't figure out for number 7 , 8, 9. let me know.
Attached Files
File Type: xml jazz.xml (1.6 KB, 3 views)
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 22
Reputation: mlohokare is an unknown quantity at this point 
Solved Threads: 0
mlohokare mlohokare is offline Offline
Newbie Poster

Re: Need help (urgent)

 
0
  #2
Mar 30th, 2009
Hi,

can you please give the xslt code which you have tried????


Cheers,
Mahesh
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 22
Reputation: mlohokare is an unknown quantity at this point 
Solved Threads: 0
mlohokare mlohokare is offline Offline
Newbie Poster

Re: Need help (urgent)

 
0
  #3
Mar 30th, 2009
Hi,

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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 46
Reputation: xml_looser is an unknown quantity at this point 
Solved Threads: 2
xml_looser xml_looser is offline Offline
Light Poster

Re: Need help (urgent)

 
0
  #4
Apr 8th, 2009
from sample
looking for Total duration

XML, XSLT and XPATH Syntax (Toggle Plain Text)
  1. <?xml version="1.0"?>
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  3. <xsl:output method="html" indent="yes"/>
  4. <xsl:key name="sum" match="//@length" use="number(translate(.,':','.'))"/>
  5. <xsl:template match="/">
  6. <xsl:apply-templates select="Specials"/>
  7. </xsl:template>
  8.  
  9. <xsl:template match="Specials">
  10. <html>
  11. <head>
  12. <title>
  13. <xsl:apply-templates select="Title"/>
  14. </title>
  15. </head>
  16. <body>
  17. <xsl:apply-templates select="CDs"/>
  18. <xsl:call-template name="question789"/>
  19. </body>
  20. </html>
  21. </xsl:template>
  22.  
  23.  
  24. <xsl:template match="CDs">
  25.  
  26. <xsl:apply-templates select="CD"/>
  27. </xsl:template>
  28. <xsl:template match="CD">
  29. <div>
  30. <p>Title: <xsl:value-of select="@title"/></p>
  31. <p>Artist: <xsl:value-of select="./Artist"/></p>
  32. <p>Total Tracks: <xsl:value-of select="count(./Tracks/Track)"/></p>
  33. <xsl:apply-templates select="Tracks"/>
  34. </div>
  35. </xsl:template>
  36. <xsl:template match="Tracks">
  37. <xsl:apply-templates select="Track"/>
  38. <p>
  39. <xsl:call-template name="timesum">
  40. <xsl:with-param name="km" select="child::Track/@length"/>
  41. </xsl:call-template>
  42. </p>
  43. </xsl:template>
  44. <xsl:template match="Track">
  45. <ul>
  46. <li>Track: <xsl:value-of select="."/></li>
  47. <li>Track Length: <xsl:value-of select="@length"/></li>
  48. </ul>
  49. </xsl:template>
  50. <xsl:template name="timesum">
  51. <xsl:param name="km"/>
  52. <xsl:param name="ak" select="1"/>
  53. <xsl:param name="min" select="0"/>
  54. <xsl:param name="hour" select="0"/>
  55. <xsl:variable name="c" select="count($km)"/>
  56.  
  57. <xsl:choose>
  58. <xsl:when test="$ak &lt;= $c">
  59.  
  60. <xsl:variable name="tmin" select="substring-after($km[$ak],':')"/>
  61. <xsl:variable name="thour" select="substring-before($km[$ak],':')"/>
  62.  
  63. <xsl:call-template name="timesum">
  64. <xsl:with-param name="ak" select="$ak+1"/>
  65. <xsl:with-param name="km" select="$km"/>
  66. <xsl:with-param name="hour" select="$hour + $thour"/>
  67. <xsl:with-param name="min" select="$min + $tmin"/>
  68. </xsl:call-template>
  69. </xsl:when>
  70.  
  71. <xsl:otherwise>
  72. <xsl:value-of select="concat('Total duration',$hour+($min -$min mod 60) div 60,':',format-number($min mod 60,'00'))"/>
  73. </xsl:otherwise>
  74. </xsl:choose>
  75. </xsl:template>
  76. <xsl:template name="question789">
  77. <h1>answer of question 7,8,9</h1>
  78. <p>Track number of ‘All Blues’ song on ‘Kind of Blue’ CD</p>
  79. <p>count(/Specials/CDs/CD[@title='Kind of Blue']/Tracks/Track[.='All Blues']/preceding-sibling::Track)+1</p>
  80. <h3>
  81. <xsl:value-of select="count(/Specials/CDs/CD[@title='Kind of Blue']/Tracks/Track[.='All Blues']/preceding-sibling::Track)+1"/>
  82. </h3>
  83. <p>Name of second track on ‘Cookin’ CD</p>
  84. <p>/Specials/CDs/CD[@title='Cookin']/Tracks/Track[2]</p>
  85. <h3>
  86. <xsl:value-of select="/Specials/CDs/CD[@title='Cookin']/Tracks/Track[2]"/>
  87. </h3>
  88. <p>Total cost to purchase all 3 CDs (UK prices)</p>
  89. <p>sum(/Specials/CDs//CD/PriceUK)</p>
  90. <h3>
  91. <xsl:value-of select="sum(/Specials/CDs//CD/PriceUK)"/>
  92. </h3>
  93. </xsl:template>
  94. </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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the XML, XSLT and XPATH Forum


Views: 578 | Replies: 3
Thread Tools Search this Thread



Tag cloud for XML, XSLT and XPATH
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC