[学校] 使用XSL转换XML演练
例如,我有一个包含信息排名PT系数的xml文件 2. 使用XSL读取XML PT数据.
<?xml version = "1.0"?> <?xml-stylesheet type="text/xsl" href="ptb2.xsl"?> <PTB2> <HeSo giatri = "1"/> <HeSo giatri = "3"/> <HeSo giatri = "2"/> </PTB2>
<?xml version = "1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:math="http://exslt.org/math" version="1.0"> <xsl:template match="/"> <xsl:variable name = "a" select="PTB2/HeSo[1]/@giatri"/> <xsl:variable name = "b" select="PTB2/HeSo[2]/@giatri"/> <xsl:variable name = "c" select="PTB2/HeSo[3]/@giatri"/> <xsl:variable name = "delta" select="$b * $b - 4 * $a * $c"/> <xsl:if test = "$delta < 0"> PT Vo nghiem </xsl:if> <xsl:if test = "$delta = 0"> PT Co nghiem kep x = <xsl:value-of select = "-$b div 2 div $a"/> </xsl:if> <xsl:if test = "$delta > 0"> PT Co 2 nghiem phan biet <br/> x1 = <xsl:value-of select = "(-$b + math:sqrt($delta)) div 2 div $a"/> <br/> x2 = <xsl:value-of select = "(-$b - math:sqrt($delta)) div 2 div $a"/> </xsl:if> </xsl:template> </xsl:stylesheet>
最新评论