XSL practice summary (2)

Source: Internet
Author: User
Tags xsl xsl file
1. Use of templates
Some encoding tables are stored in the database, but some Chinese characters are displayed.
In this case, we can define an XSL file that stores data. I have defined a codetab. XSL

Reference this file to the archive. XSL file, which is the file to display the real data.
Here is an example of a diploma: < XSL: Include Href = "Codetab. XSL" />
< XSL: Variable Name = "Oppeducation" >
< XSL: Call-template Name = "Getdegree" >
< XSL: With-Param Name = "Degree" Select = "Archives/education" />
</ XSL: Call-template >
  </ XSL: Variable >

Http://www.cnblogs.com/goody9807
Codetab. XSL < XSL: Template Name = "Getdegree" >
< XSL: Param Name = "Degree" />
< XSL: Variable Name = "Degreemapper" >
< Item >
< Name > High School and below </ Name >
< Value > 1 </ Value >
</ Item >
< Item >
< Name > University </ Name >
< Value > 2 </ Value >
</ Item >
< Item >
< Name > Master </ Name >
< Value > 3 </ Value >
</ Item >
< Item >
< Name > Doctor </ Name >
< Value > 4 </ Value >
</ Item >
< Item >
< Name > Postdoctoral </ Name >
< Value > 5 </ Value >
</ Item >
</ XSL: Variable >
< XSL: value- Select = "Exslt: node-set ($ degreemapper)/item [value = $ degree]/name" />
  </ XSL: Template >

Note: The extended XSLT is used here, so you need to define xmlns: exslt above= "Http://exslt.org/common" 
<XSL: stylesheetVersion= "1.0"Xmlns: bithelper= "Bithelper"Xmlns: math= "Http://exslt.org/math"Xmlns: exslt= "Http://exslt.org/common"Xmlns: XSL= "Http://www.w3.org/1999/XSL/Transform">

Finally, in actual use<TD>Education level:<XSL: value-Select= "$ Oppeducation"/> </TD>

Http://www.cnblogs.com/goody9807

2. Convert the date format in XSL

The date namespace must be referenced in the topic definition.<XSL: stylesheetVersion= "1.0"Xmlns: Date= "Http://exslt.org/dates-and-times"Xmlns: XSL= "Http://www.w3.org/1999/XSL/Transform">

You can use a mask to convert the date format you want when the date appears.

< TD > Date of birth: < XSL: value- Select = "Date: format-date (archives/birthday, 'yyyy-mm-dd Day ')" /> </ TD >

3. Methods in math namespaces of exslt are used in XSL.

< XSL: Variable Name = "Powernumbers" >
< XSL: For-each Select = "Exslt: node-set ($ matchincomemapper)/item/value" >
< Value >
< XSL: value- Select = "Math: Power (2, number (.)-1 )" />
</ Value >
</ XSL: For-each >
</ XSL: Variable >

For more information about exslt, see:
Http://www.exslt.org/

4. How to concatenate strings in XSL < XSL: For-each Select = "Exslt: node-set ($ matchincomemapper)/item [bithelper: isselected (number ($ matchincome), value)]" >
< XSL: If Test = "Position () & gt; 1" > , </ XSL: If >
< XSL: value- Select = "Name" />
</ XSL: For-each >

The position method is the built-in method of XSL, which means to obtain the position in each loop. The above loop can achieve the effect of concatenating strings.
For example, if you have multiple education backgrounds:
University, PhD, Master

5. Reference Methods in Java classes in XSL
First, I define a bithelper class.

Import Java. util. * ;
Public   Class Bithelper {
Public   Static   Boolean Isselected ( Long Source, Int Pos) {
Return(Source&(1<(Pos-1)))>0;
}
Public   Static   Int Randomnumber ( Int Minnumber, Int Maxnumber) {

Random RND=NewRandom ();
ReturnRND. nextint (maxnumber-Minnumber+1)+Minnumber;
}
Static   Void Main (string [] ARGs) {
Bithelper BH=NewBithelper ();
System. Out. Print (bH. isselected (8,4));
}
}

Http://www.cnblogs.com/goody9807

< XSL: variable name = " Randomnumber " Select = " Bithelper: randomnumber (1, count ($ destlovetypeset )) " />

Note that the namespace must be referenced in the first line of the page.<XSL: stylesheetVersion= "1.0"Xmlns: bithelper= "Bithelper"Xmlns: exslt= "Http://exslt.org/common"Xmlns: Random= "Http://exslt.org/random"Xmlns: XSL= "Http://www.w3.org/1999/XSL/Transform">

I hope to have more friends with this knowledge!

RelatedArticle: XSL practice summary (1)

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.