Today, we are studying the various operators of XSL to meet the requirements for writing more flexible XSL styles.
Table 1. Operators and special characters
Operator |
Description |
/ |
Select a child element and return the direct child element of the left element. If "/" is on the 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
Comparison Operators |
Optional |
Description |
And |
$ And $ or && |
Logic and |
Or |
$ Or | |
Logic or |
Not () |
$ Not $ |
Non-logical |
Table 3 Relational operators
= |
$ EQ $ |
Equal |
= |
$ Ieq $ |
Equal (Case Insensitive) |
! = |
$ Ne $ |
Not Supported |
|
$ Ine $ |
Unequal (Case Insensitive) |
< |
$ Lt $ |
Less |
|
$ ILT $ |
Less than (Case Insensitive) |
<= |
$ Le $ |
Less than or equal |
|
$ Ile $ |
Less than or equal to (Case Insensitive) |
> |
$ GT $ |
Greater |
|
$ IBS $ |
Greater than (Case Insensitive) |
> = |
$ 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 = 'webdeveloper']">
<Tr> <TD> <XSL: value-of select = "name"/> </TD>
<TD> <XSL: value-of select = "E-mail"/> </TD>
</Tr>
</XSL: For-each>
</Table>
Note:
1. [] ── indicating 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' -- filter 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 $'2014/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 '──The search condition. If "<" is used here, it will be incorrect. Therefore, "$ lt $" indicates that the value is less.
2.Skill [0] ── ─Indicates that the first skill item is selected.
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 the value of the current tag.
I believe you should note that some functions appear in the previous and current examples, suchIndex (), formatindex (), childnumber ()Maybe you still don't fully understand the meaning, right? Stay tuned for the next lesson.