XSL (2)-XSL Operators

Source: Internet
Author: User
Tags xsl
Table 1. Operators and special characters

Operator Description
/ Select a child element to return the direct child element of the left element. If "/" is on the far left, select the direct child element of the root node.
// Recursive descent: searches for the specified Element regardless of depth. If it is on the leftmost side, it indicates recursive descent from the root node to search for the specified element.
. Indicates the current element.
* Wildcard character. Select any element, regardless of the name.
@

 

Get the property value as the prefix of the property name

@*

 

Wildcard character. Select any attribute, regardless of the name.

: Delimiter used by the name to separate the prefix used by the name from the element or attribute name.
! * Apply the specified method on the relevant Node
()* Group to specify the priority
[] Apply filter Style
[] * Subscript operator, used to indicate elements in a collection

Table 2 logical operators

Optional Description
And $ and $ or && Logic and
Or $ or | Logic or
Not () $ not $ Non-logical

Table 3 Relational operators

Optional Description
= Or $ EQ $ Equal
= Or $ ieq $ Equal (Case Insensitive)
! = Or $ ne $ Not Supported
$ Ine $ Unequal (Case Insensitive)
<Or $ lt $ Less
$ ILT $ Less than (Case Insensitive)
<= Or $ le $ Less than or equal
$ Ile $ Less than or equal to (Case Insensitive)
> Or $ GT $ Greater
$ IBS $ Greater than (Case Insensitive)
>=Or $ Ge $ Greater than or equal
$ IgE $ Greater than or equal to (Case Insensitive)
$ All $ Set operator. If all items in the set meet the conditions, true is returned"
$ Any $ Set operator. If any item in the Set meets the conditions, "true" is returned"
| Set operator, returns the union of two sets

Example 1:

Find the name and e-mail of the person with "Web development" skills from his/her resume. Assume that the document structure is as follows:

<Document>
<Resume>
<Name> name </Name>
<Sex> sex </sex>
<Birthday> birthday </birthday>
<Skill> skill1 </skill>
<Skill> skill2 </skill2>
...
<Skill> skilln </skill>
</Resume>
<Resume>
...
</Resume>
...
</Document>

Find out the names of all persons with web development skills and e-mail's XSL document structure from the above structure's resume:

<Table border = "1" cellspacing = "0">
<TH> name </Th> <TH> email </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>

Note:

1. [] ── indicates the selection criteria. Only resumes meeting the criteria are displayed.

2. $ any $ -- because each person has multiple skills, add $ any $ as the prefix so that all skills can be compared.

3. Skill = 'web developer' -- filtering condition.

Example 2,

For example, if you want to select the name, skill, and e-mail of the person born before January 1, the corresponding XSL document structure is as follows (assuming the birthday format is yyyy/mm/DD ):

<Table border = "1" cellspacing = "0">
<TH> name </Th> <TH> Skill </Th> <TH> email </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>

Note:

1. Birthday $ lt $'2014/1/1' -- search condition. If you use "<" here, it will be incorrect. Therefore, use "$ lt $" to indicate that it is less.

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

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

4. XSL: value-of select = "." ── indicates selecting the value of the current tag.

I believe you should note that some functions, such as index (), formatindex (), childnumber (), appear in the previous and current examples (), maybe you still don't fully understand the meaning, right? 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.