Using XPath Functions and Operators - Exercise

Contact Us or call 1-877-932-8228
Using XPath Functions and Operators - Exercise

Using XPath Functions and Operators

Duration: 15 to 25 minutes.

In this exercise, you will practice using XPath functions.

  1. Open XPath/Exercises/XPathFunctions.xsl for editing.
  2. There are several xsl:value-of elements. For each, replace the text XPATH in the select attribute with an actual XPath according the instructions in the comments.
  3. To test your solutions, transform XPath/Exercises/BusinessLetter3.xml against XPath/Exercises/XPathFunctions.xsl.


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
	<xsl:output method="xml" indent="yes"/>
	<xsl:template match="/">
	<!--Output the value of the FirstName child of the first Name element
	 that doesn't have a Title attribute-->
		<xsl:value-of select="//Name[not(@Title)]/FirstName"/>
	<!--Output the street number of Webucator Inc's 
			street address (i.e, 4933)-->
	<xsl:value-of select="substring-before(//Para/Person/Address/Street,' ')"/>
	<!--Output the paragraph text of the paragraph that contains 
			Bill Smith's email address-->
		<xsl:value-of select="//Para[Email='']"/>
	<!--Output the number of elements contained in 
			Joshua Lockwood's Address-->
		<xsl:value-of select="count(//Recipient/Address/*)"/>
	<!--Output the number of elements the contain 
			the word "Lockwood" (should be 3)-->
		<xsl:value-of select="count(//*[contains(text(),'Lockwood')])"/>