Testing with []
- Test whether a certain condition is true, for example:
- student element with a child name element
<xsl:template match="student[name]">
- Any element that has a name element
<xsl:template match="*[name]">
- student element that has either hw1 or hw2 element
<xsl:template match="student[hw1 | hw2]">
Example: Name of the student with id 'js'
XSL Style Sheet:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="course">
<NAME>
<xsl:apply-templates select="student"/>
</NAME>
</xsl:template>
<xsl:template match="text()">
</xsl:template>
<xsl:template match="student[@id = 'js']">
<xsl:value-of select="name"/>
</xsl:template>
</xsl:stylesheet>