The <xsl:value-of/> element uses the select attribute to state the XPath of the element for processing and is always an empty element.
This XML file was used for all the examples.
Example 1
This example uses <xsl:template match="EmployeeListing"> and <xsl:apply-templates/>.
It also states an ADDITIONAL <xsl:template match>. This additional <xsl:template match> states the path value for the ChildElement of EmployeeListing which is Employee. (<xsl:template match="Employee">)
This additional <xsl:template match> element does not need to state the ParentElement of EmployeeListing because EmployeeListing was already stated within the top level <xsl:template match="EmployeeListing"> element.
Within the <body> element of the HTML, a table is used for layout. Within each <td> cell the <xsl:value-of select="path"> element states the select attribute using each ChildElement of Employee.
<td style="font-family:arial;">
<xsl:value-of select="FirstName"/>
</td>
View the XSL stylesheet
View result
Example 2
This example uses <xsl:template match="EmployeeListing/Employee"> and <xsl:apply-templates select="ChildElement name of Employee"/>
Within the <body> element of the HTML, a table is used for layout. Within each <td> cell the <xsl:apply-templates select="path"> element states the select attribute using each ChildElement of Employee.
<td style="font-family:arial;">
<xsl:apply-templates select="FirstName"/>
</td>
View the XSL stylesheet
View result
Example 3
This example uses <xsl:template match="/"> and <xsl:value-of select="EmployeeListing/Employee/ChildElement name of Employee"/>
Note how the processor ONLY returns the FIRST instance of the Employee element's content from its ChildElements. This is due to being very specific for the value of the attribute select's path. (The forward slash stated for the match attribute states the relative path of a ParentElement.)
View the XSL stylesheet
View result
Example 4
This example uses <xsl:template match="/"> and <xsl:apply-templates select="EmployeeListing"/>
It also states an ADDITIONAL <xsl:template match>. This additional <xsl:template match> states the path value for the ChildElement of EmployeeListing which is Employee. (<xsl:template match="Employee">)
This additional <xsl:template match> element does not need to state the ParentElement of EmployeeListing because EmployeeListing was already stated as the top level <xsl:template match="EmployeeListing"> ParentElement.
View the XSL stylesheet
View result |