Match Pattern-XSL Tutorial-4_xml basics

Source: Internet
Author: User
The <xsl:template> element defines the rules for matching nodes (match, where "/" matches the entire document), used in Apply-template
The syntax rules are:
<xsl:template
Name= "Name"
Match= "pattern"
Mode= "mode"
priority= "Number" >
<!--Content: (<xsl:param>*,template)-->
</xsl:template>

which
Name template names
Match XPath statement, specifying criteria
Mode mode, such as red, blue and other styles
Priority priority, for numbers
For example, the following XML file: <?xml version= "1.0" encoding= "GB2312"?>
<?xml:stylesheet type= "text/xsl" href= "userlist_template.xsl"?>
<Users>
<user isadmin= ' OK ' >
<Name>5do8</Name>
<ID>1</ID>
<Contact>
<QQ>369987789</QQ>
<EMAIL>service@163.com</EMAIL>
</Contact>
</User>
<User>
<Name>cjjer</Name>
<ID>2</ID>
<Contact>
<QQ>369987789</QQ>
<EMAIL>service@163.com</EMAIL>
</Contact>
</User>
<User>
<Name>Admin</Name>
<ID>3</ID>
<Contact>
<QQ>369987789</QQ>
<EMAIL>service@163.com</EMAIL>
</Contact>
</User>
</Users>
The template used (userlist_template.xsl) is:
<?xml version= "1.0" encoding= "GB2312"?>
<xsl:stylesheet version= "1.0" xmlns:xsl= "Http://www.w3.org/1999/XSL/Transform" >
<xsl:template match= "/" >
<body>
<xsl:apply-templates/>
</body>
</xsl:template>
<xsl:template match= "User" >
<p>
<xsl:apply-templates select= "Name"/>
<xsl:apply-templates select= "ID"/>
</p>
</xsl:template>
<xsl:template match= "Name" >
Name: <span style= "color: #BB0000" >
<xsl:value-of select= "." /></span>
<br/>
</xsl:template>
<xsl:template match= "ID" >
ID: <span style= "color: #808000" >
<xsl:value-of select= "." /></span>
<br/>
</xsl:template>
</xsl:stylesheet>

You can display user information as a list.

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.