![]() "I created him for good, but he's turned out evil!"Įach time a select attribute is processed, it is evaluated in terms of the current node. Discovering the secrets of life and creationģ. The previous template produces these results: Section 1. "I created him for good, but he's turned out evil!" Here’s a sample that selects all elements inside a element and then uses a second element to select all the elements inside each element: ĭiscovering the secrets of life and creation (Remember that the boolean negation of zero is true.) For obfuscation bonus points, we could code the second element as. If position() mod 4 = 3, the background color will be whitesmoke.Ī couple of minor details: in this example, we could replace the element with that is logically equivalent to the example as coded previously. Finally, we use an element to specify whitesmoke as the default case. The use of the mod operator here is the most efficient way to cycle between the various options. The next three elements check the position of the current element. (If the bgcolorĪttribute is coded, the XPath expression returns a node-set containing a single attribute node.) Our first test is to see if the bgcolor attribute of the element exists if it does, we use that value for the background color and the and other elements are ignored. In this sample, we use to generate the value of the bgcolor attribute of the element. If the bgcolor attribute is coded on the element, the value of that attribute is used as the color otherwise, the sample uses the position() function and the mod operator to cycle the colors between papayawhip, mintcream, lavender, and whitesmoke. Here’s a sample element that sets the background color of the table’s rows. If no such elements exist in the current context, the test attribute is false. If the current context contains one or more elements that contain a element in turn, the test attribute is true. The XPath expression section/section returns a node-set. The boolean function false() always returns the boolean value false. On the other hand, the expressions not(0) and not(-0) are always true. The literal 3 evaluates to true, so its negation is false. The value of the nonempty string, confusing as it is, doesn’t matter. Because the string has a length greater than zero, the test attribute is always true. As before, we used single quotes inside double quotes to specify that this is a literal string. This test attribute is always true because the string has a length greater than zero, not because its value happens to be the word “ true.” Īnother trick example this test attribute is always true. Notice that in this case we used single quotes inside double quotes to specify that this is a literal string, not an element name. The strings true and false don’t have any special significance in XSLT. The XSLT processor interprets the value true as an XPath expression that specifies all elements in the current context. This test attribute is true only if there is at least one element in the current context. Therefore, this test attribute is always true. The boolean function true() always returns the boolean value true. (Of course, if x is a boolean value, true is true and false is false.) If it is a number, then the test attribute is true only if the number is anything other than positive zero, negative zero, or NaN. If it is a node-set, then the test attribute is true only if the node-set has at least one member. If it is a string, then the test attribute is true only if the string has a length greater than zero. If the count() function returns a value greater than or equal to 2, the test attribute is true. This is a boolean expression because it uses the greater-than-or-equal boolean operator. See Section B.4.2 for more information on this topic. If you need to use the less-than operator ( =) operators. You’re always safe using > here, although some XSLT processors process the greater-than sign correctly if you use > instead. Notice that we used > instead of > in the attribute value. (If you want to implement an if-then-else statement, check out the element described in the next section.) If test evaluates to false, then the contents of the element are ignored. If the value of test evaluates to the boolean value true, then all elements inside the are processed. ![]() ![]() The element has only one attribute, test. The element, surprisingly enough, implements an if statement.
0 Comments
Leave a Reply. |