Learn xsl with me (vi)

Source: Internet
Author: User
Tags logical operators xsl

Today we learn the various operators of XSL to meet the requirements for writing more flexible XSL styles.

table I, operators and special characters

Operator

Describe

/

Select the child element to return the immediate child element of the left element; if "/" is on the leftmost side, the direct child element of the selected root node

//

Recursive descent, regardless of depth, searches for the specified element, if the leftmost represents a recursive descent from the root node to search for the specified element

.

Represents the current element

*

Wildcard, select any element, regardless of name

@

Gets the attribute value, as the prefix for the property name

@*

wildcard character, select any attribute, regardless of name

:

Name Scope delimiter separates the name scope prefix from the element or attribute name

!*

Apply the specified method on the related node

( )*

grouping, specifying priority order explicitly

[ ]

Apply Filter Style

[ ]*

Subscript operator, which is used to indicate the element in the collection

Table II, logical operators

Comparison operators

Optional options

Describe
and $and $ or && Logic and
Or $or $ or | | Logical OR
Not () $not $ Logical Non-

Table III, relational operators

= $eq $ Equal
= $ieq $ Equal (case insensitive)
!= $ne $ Range
$ine $ Unequal (case insensitive)
< $lt $ Less than
$ilt $ Less than (case insensitive)
< = $le $ Less than or equal
$ile $ Less than or equal (case insensitive)
> $GT $ Greater than
$igt $ Greater than (case insensitive)
>= $ge $ Greater than or equal
$ige $ Greater than or equal (case insensitive)
$all $ Set operator that returns true if all items in the collection meet the criteria
$any $ Set operator that returns true if any item in the collection satisfies the condition
| Set operator, which returns a union of two collections

Example One:

Find the names and e-mails of people with "web development" skills from your CV. Suppose the document structure looks like this:

< document >

< resume >

< name >name</name >

< sex >sex</sex >

< birthday >birthday</birthday >

< skill >skill1</skill >

< skill >skill2</skill2 >

... ..

< skill >skilln</skill >

</resume >

< resume >

... ..

</resume >

... ..

</document >

The XSL document structure for the name and e-mail of all people with "web development" skills is found in the CVS of the above structure as follows:

< TABLE border= "1" cellspacing= "0" >

< th > name </th >< TH >E-Mail</th >

< Xsl:for-each select= "Resume [$any $ Skill= ' web development ']" >

< TR >< TD >< xsl:value-of select= "name"/></td >

< TD >< xsl:value-of select= "e-mail"/></td >

</tr >

</xsl:for-each >

</table >

Description

1.[]─── said the selection criteria, only meet the conditions of the resume is displayed;

2. $any $── Because each person has multiple skills, add $any$ as a prefix so that everyone's skills can be compared;

3.skill= ' web Development '--filter criteria

example Two,

For example, if you want to select the names, skills, and e-mails of people born before 1977/1/1, the corresponding XSL document structure is as follows (assuming the birthday format is YYYY/MM/DD):

< TABLE border= "1" cellspacing= "0" >

< th > Names </th >< th > Skills </th >< th >E-Mail</th >

< Xsl:for-each select= "Resume [birthday $lt $ ' 1977/1/1 ']" >

< TR >

< TD >< xsl:value-of select= "name"/></td >

< TD >< xsl:value-of select= "skill [0]"/>

< Xsl:for-each select= "skill [index () >0]" >,

< xsl:value-of select= "." />

</xsl:for-each >

</td >

< TD >< xsl:value-of select= "e-mail"/></td >

</tr >

</xsl:for-each >

</table >

Description

1. Birthday $lt $ ' 1977/1/1 ' --search conditions where the use of ' < ' is error, so use "$lt $" to indicate less than.

2. Skill [0]─── indicates the first item to select skill

3. Skill [index () >0]─── indicates that the item after the second item of the skill is selected (including the second item)

4. xsl:value-of select= "." ─── to select the value of the current tag

I believe you should note that in the previous and this example there are some functions, such as index (), Formatindex (), Childnumber (), perhaps we do not fully understand the meaning of it. Stay tuned for the next lesson.

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.