Grammar
3.5 Xsl:choose, Xsl:when and Xsl:otherwise
The XSL:IF syntax does not have an else attribute. If we are going to make multiple choices, we need to use the Xsl:choose/xsl:when/xsl:otherwise series Process Control syntax. For specific use, see the following XSL file example:
<xsl:template match= "People" >
<xsl:choose>
<xsl:when test= "@name = ' Ajie '" >
<b><xsl:value-of select= "@name"/></b>
</xsl:when>
<xsl:when test= "@name" >
<i><xsl:value-of select= "@name"/></i>
</xsl:when>
<xsl:otherwise>
No name available
</xsl:otherwise>
<xsl:choose>
</xsl:template>
Description: First in the People node to find <name> attribute value of Ajie elements, if found, will ajie in bold output; If you do not find a <name> element with a value of Ajie, all <name> The value of the element is output in italics, and if no <name> element is found, the "no" is displayed.
Name available ".
3.6 Xsl:sort
In XSLT, the elements of an XML source document can be reordered, and the ordering syntax is xsl:sort. For example: The following code is to sort the document elements by name.
<xsl:template match= "People" >
<xsl:apply-templates select= "Person" >
<xsl:sort select= "@name"/>
</xsl:apply-templates>
</xsl:template>
These are the main syntaxes of the elements of XSLT, and many other syntaxes, such as import, include, element, attribute, number, param, and so on, are not explained here. Our aim is to give you a basic idea of the syntax of XSLT, and to understand XSLT as a powerful function of translating languages.