Special Characters in XSLT 1.0 with HTML Entity Alternatives
In XSLT 1.0, certain characters have special meanings within the language, and in some contexts, you need to represent these characters using their HTML entity equivalents to avoid conflicts or errors in the code. Below are some of the most common characters used in XSLT 1.0 that have HTML entity alternatives.
Common Special Characters and Their HTML Entity Codes
Greater-than sign (>)
The greater-than symbol (>) is used in XSLT for comparisons and is a reserved character in XML. When writing XSLT code, it’s often necessary to use the HTML entity > to represent it.
- <xsl:value-of select="price > 100"/>
Less-than sign (<)
Similar to the greater-than sign, the less-than symbol (<) is reserved in XML. You must use the HTML entity < to represent it in contexts where it isn't part of XML syntax.
- <xsl:value-of select="quantity < 10"/>
Ampersand (&)
The ampersand symbol (&) is used to begin an entity reference in XML and thus must be written as & to avoid confusion with character references.
- <xsl:value-of select="name & description"/>
Quotation mark (")
In XML and XSLT, double quotation marks (") are used for attribute values. To include them within the value of an attribute, you should use the entity ".
- <xsl:value-of select="description "special offer""/>
Apostrophe (')
Similar to the quotation mark, the apostrophe (') is reserved for attribute values and is represented as ' when needed inside an attribute.
- <xsl:value-of select="name 'John'"/>
Line break
In XSLT, a line break or newline character can be represented using the HTML entity . This can be useful when you want to insert a line break in the output of the transformation or format text in a more readable way.
- <xsl:value-of select="'Line 1 Line 2'"/>
Why Use HTML Entity Codes?
In XSLT 1.0, certain characters have specific meanings, such as < and >, which are used for defining tags. If you try to use these characters directly in your XSLT expressions or within attribute values, the XML parser may misinterpret them, leading to errors or unexpected results. By using HTML entities like <, >, &, and others, you ensure that these characters are treated as literal text rather than XML syntax.
By understanding and using these HTML entities, you can safely include special characters in your XSLT code without causing parsing issues.