Follow me. The combination and application of XSL (8) script and XSL

Source: Internet
Author: User
Tags eval xsl xsl file

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);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.