Understanding the selection patterns of XSL

Source: Internet
Author: User
Tags xmlns xsl xsl file

What is selection mode

The select Pattern statement extracts data from XML as a simple way to get data, which has a select attribute that selects data from specific node names in the XML

Note that each XSL file needs to import the XSL namespace, http://www.w3.org/TR/WD-xsl, for example, after the XML header declaration:

<p xmlns:xsl="http://www.w3.org/TR/WD-xsl">

1, <xsl:for-each>

This statement selects a condition individually (select) and applies the condition. For example, you have a list of users with the following databases:

<?xml version="1.0" encoding="GB2312"?>
<Users>
<User>
<Name>5do8</Name>
<ID>1</ID>
<Professional>.NET,PHP Design</Professional>
</User>
<User>
<Name>cjjer</Name>
<ID>2</ID>
<Professional>DataBase Manage</Professional>
</User>
</Users>

You need to output only the full Name column, here are two questions:

1: You need to select the data below each user node, that is, to locate the user node, we use the select below For-each.

2: You need to select the name node, we use the select below value-of.

To create an XSL file:

<?xml version="1.0" encoding="GB2312"?>
<p xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:for-each select="Users">
<BODY>
<xsl:for-each select="User">
<xsl:value-of select="Name" /> </xsl:for-each>
</BODY>
</xsl:for-each></p>

Save as userlist_for-each.xsl. Increase in the second line of the XML file:

<?xml:stylesheet type="text/xsl" href="UserList_for-each.xsl"?>

The effect is visible in browsers above ie5+.

For-each also supports sorting, order-by statements, which are separated by semicolons (;) as a list of sorting criteria. Adding a plus sign (+) before a list element means that the contents of this tag are sorted in ascending order, and a minus sign (-) is used to indicate the order of reverse orders. As a simplified representation, the sorting criteria list is a sequence of tokens that are specified by select, separated by (;) between each tag.

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.