![]() |
|
|
|
| ||||||
|
Welcome to the The ProgrammersTalk Community forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
![]() |
![]() | | LinkBack | Thread Tools | Display Modes | ![]() |
| |||
| XSLT assignment I am working on my XSLT homework. I got stuck at one point and don't know what to do. Please help. There's 3 files, golf.xml, golf.css, and golf.xsl. This is the part I can't figure out on my xslt doc - declare a variable named backNineScoreText, setting the value of the variable to the text string returned by calling the formatScore template using the value of the backNineScore variable for the scoreValue parameter. I have created the named template for formatScore. Here it is: <xsl:template name="formatScore"> <xsl:param name="scoreValue" select="golfer//score" /> <xsl:choose> <xsl:when test="$scoreValue = 0"> <xsl:text>E</xsl:text> </xsl:when> <xsl:otherwise> <xsl:call-template name="formatScore"> <xsl:with-param name="scoreValue" select="format-number($scoreValue, '-#;+#')" /> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:template> Then I try to apply this to a calcScores template (that's what the assignment wants). I highlighted the part I need to revise. I don't understand what I need to do. <xsl:template name="calcScores"> <xsl:param name="currentRound" /> <xsl:param name="currentHole" /> <xsl:variable name="parTotal" select="sum(//par[@holeNumber <= $currentHole])" /> <xsl:variable name="golferTotal" select="sum($currentRound/score[@holeNumber <= $currentHole])" /> <xsl:variable name="currentScore" select="$parTotal - $golferTotal" /> <xsl:variable name="currentScoreText"> <xsl:value-of select="$currentScore" /> </xsl:variable> <td><xsl:value-of select="$currentScoreText" /></td> <xsl:choose> <xsl:when test="$currentHole = 18"> <xsl:variable name="backNinePar" select="sum(//par[@holeNumber > 9 and @holeNumber <= 18])" /> <xsl:variable name="backNineGolfer" select="sum($currentRound/score[@holeNumber > 9 and @holeNumber <= 18])" /> <xsl:variable name="backNineScore" select="$backNinePar - $backNineGolfer" /> <xsl:variable name="backNineScoreText"> <xsl:value-of select="$backNineScore" /> </xsl:variable> <td class="sub"><xsl:value-of select="$backNineScoreText" /></td> <td class="final"><xsl:value-of select="$currentScoreText" /></td> </xsl:when> <xsl:when test="$currentHole = 9"> <td class="sub"><xsl:value-of select="$currentScoreText" /></td> </xsl:when> </xsl:choose> Please also see my attachment for all my files. basically this is what i need to achieve, If the number for Round Total is = 0, it should display text string of "E". A negative value should be displayed as - value, and the positive value should be displayed as + value. Thanks. |
| |
![]() |
| Thread Tools | |
| Display Modes | |
| |