xslt - xml to xml conversion using XSTL -
i have input xml file named copystud.xml:
<!-- new xml document created editix xml editor (http://www.editix.com) @ thu aug 31 20:55:30 ist 2017 --> <?xml-stylesheet type="text/xsl" href="copystudent.xsl"?> <player> <name>niyut</name> <score> <game1>95</game1> <game2>70</game2> <game3>80</game3> </score> </player>
i need output :
<outcome> <playername>niyut</playername> <total>237</total> <maxscore>300</maxscore> <nextlevel>congrats next level</nextlevel> </outcome>
and xsl file copystudent.xsl:
<?xml version="1.0" encoding="utf-8" ?> <!-- new xslt document created editix xml editor (http://www.editix.com) @ fri sep 01 11:48:27 ist 2017 --> <xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns:xs="http://www.w3.org/2001/xmlschema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xdt="http://www.w3.org/2005/xpath-datatypes" xmlns:err="http://www.w3.org/2005/xqt-errors" exclude-result-prefixes="xs xdt err○ fn"> <xsl:output method="html" indent="yes"/> <xsl:template match="/"> <html> <body> evaluating players <table> <tr> <td>totalscore</td> <td> <xsl:variable name ="tot_score" select="sum(.//game1 | .//game2 | .//game3)" /> <xsl:value-of select="$tot_score" /> </td> <td>maxscore</td> <td> <xsl:variable name="subj_count" select="count(/player/score/*)"/> <xsl:value-of select="count(/player/score/*)*100"/> </td> <td>evalv</td> <td> <xsl:value-of select="$tot_score div $subj_count" /> </td> </tr> </table> </body> </html> <xsl:apply-templates/> </xsl:template> </xsl:stylesheet>
i can't find average score of players , display whether going next level or not. max_score each game 100.
i need xml xml transformation , not html. please guide me solve this.
variables in xslt locally scoped block in declared. need move variable declarations start of template, , can used anywhere within template
try xslt. note have changed template match player
simplifies xpath expressions in code
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="html" indent="yes"/> <xsl:template match="/player"> <xsl:variable name ="tot_score" select="sum(score/*)" /> <xsl:variable name="subj_count" select="count(score/*)"/> <html> <body> evaluating players <table> <tr> <td>totalscore</td> <td> <xsl:value-of select="$tot_score" /> </td> <td>maxscore</td> <td> <xsl:value-of select="$subj_count * 100"/> </td> <td>evalv</td> <td> <xsl:value-of select="format-number($tot_score div $subj_count, '0.##')" /> </td> </tr> </table> </body> </html> </xsl:template> </xsl:stylesheet>
Comments
Post a Comment