Sometimes, we might want XML documents to be output with some statistical information or something like numbers, and it's not easy to make use of the previous knowledge. Two new elements <xsl:eval> and <XSL:SCRIPT> will be introduced today, so that we can easily handle this challenge.
<xsl:eval>
Meaning: Computes a script expression, outputting a text string.
Grammar:
<xsl:eval language= "Language-name" >
Property:
language── the name of the scripting language used, the available attributes are "JavaScript", "JScript", "VBScript", "VBS", and so on, and the default is "JScript".
<xsl:script>
Meaning: Declares a global variable or defines a function.
Grammar:
<xsl:script language= "Language-name" >
Properties: With <xsl:eval>
Example:
I wonder if you still have an impression of the example in the fourth issue of "Learning xml"? The XML document does not have a resume number, but the output has an uppercase Roman numeral ordinal. A slightly more complicated example will be cited today:
If we write a year-end production table, which requires a subtotal, the usual practice is to calculate it in advance, now do not have to, we can only give a single statistic, display when the subtotal one. Please find the fourth phase of "Follow me xml", the XML file does not have to be modified, and the XSL file is modified as follows:
<?xml version= "1.0" encoding= "GB2312"?>
<xsl:stylesheet xmlns:xsl= "Http://www.w3.org/TR/WD-xsl" >
<xsl:template match= "/" >
<body><xsl:apply-templates select= "Document"/></body>
</HTML>
</xsl:template>
<xsl:template match= "Document" >
<table border= "1" cellspacing= "0" >
<TH> Team </TH>
<TH> First quarter </TH>
<TH> Two quarterly </TH>
<TH> Three quarterly </TH>
<TH> Four Quarterly </TH>
<xsl:apply-templates select= "The/>"
<TR><TD> Subtotal </TD>
<td><xsl:eval>total (This, "Q1") </xsl:eval></TD>
<td><xsl:eval>total (This, "Q2") </xsl:eval></TD>
<td><xsl:eval>total (This, "Q3") </xsl:eval></TD>
<td><xsl:eval>total (This, "Q4") </xsl:eval></TD>
</TR>
</TABLE>
<xsl:script>
function Total (node,q)
{
Temp=0;
mark= '/document/report/' +q;
V=node.selectnodes (Mark);