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.