Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Web Design & Development

  • Print
  • + Share This
This chapter is from the book

More XPath Functions

In addition to the XPath functions detailed in this chapter, here are some additional functions you might find useful. For a full list of the functions in XPath Version 1.0, see www.w3.org/TR/xpath#corelib.

x s l t
 <xsl:template match="history">
 ...
  <xsl:value-of select="story"/>
  <br /><br />

Figure 4.23. To complete the output of the wonders-master.xml document, I add the story element to the History section. See Figure 4.23 below for a screenshot of the final HTML.

Figure 4.24

Figure 4.24 After all the XSLT and XPath work, here is screenshot of the final HTML output!

Node Functions:

  • name(node-set) returns the first node in the specified node set, and name() returns the name of the current node.
  • id(id-str) returns all the elements that have an ID equal to id-str.

String Functions:

  • contains(str1, str2) returns True if str1 contains str2, otherwise returns False.
  • string-length(str1) returns the number of characters in str1, while string-length() returns the number of characters in the current node.
  • normalize-space(str1) returns str1 with all leading and trailing white space removed, and sequences of white space replaced with a single space. normalize-space() performs the same action on the current node.

Boolean Functions:

  • not(expression) returns True if expression evaluates to False, and returns False if expression evaluates to True.
  • | (a vertical bar; often located above the \ on your keyboard). Although it’s technically not a function, it is used to combine two node sets into one.
  • + Share This
  • 🔖 Save To Your Account