943,594 Members | Top Members by Rank

Ad:
Mar 27th, 2009
0

Need help (urgent)

Expand Post »
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, 10 views)
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dollycharm is offline Offline
7 posts
since Mar 2009
Mar 30th, 2009
0

Re: Need help (urgent)

Hi,

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


Cheers,
Mahesh
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mlohokare is offline Offline
22 posts
since Oct 2008
Mar 30th, 2009
0

Re: Need help (urgent)

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mlohokare is offline Offline
22 posts
since Oct 2008
Apr 8th, 2009
0

Re: Need help (urgent)

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
Reputation Points: 16
Solved Threads: 21
Junior Poster
xml_looser is offline Offline
178 posts
since Apr 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in XML, XSLT and XPATH Forum Timeline: help with xsl for avg - ASAP
Next Thread in XML, XSLT and XPATH Forum Timeline: XML pagination





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC