XPath Expressions Overview for SLAX
XPath expressions can appear
either as the contents of an XML element or as the contents of an expr
(expression) statement. In either case, the value
is translated to either an <xsl:text>
element, which outputs literal text, or to an <xsl:value-of>
element, which extracts data from an XML structure.
You encode strings using quotation marks (single or double).
The concatenation operator is the underscore (_
), as in PERL 6.
In this example, the contents of the <three>
and <four>
elements are identical,
and the content of the <five>
element
differs only in the use of the XPath concat()
function. The resulting output is the same in all three cases.
<top> { <one> "test"; <two> "The answer is " _ results/answer _ "."; <three> results/count _ " attempts made by " _ results/user; <four> { expr results/count _ " attempts made by " _ results/user; } <five> { expr results/count; expr " attempts made by "; expr results/user; } <six> results/message; }
The XSLT equivalent is:
<top> <one><xsl:text>test</xsl:text></one> <two> <xsl:value-of select='concat("The answer is ", results/answer, ".")'/> </two> <three> <xsl:value-of select='concat(results/count, " attempts made by ", results/user)'/> </three> <four> <xsl:value-of select='concat(results/count, " attempts made by ", results/user)'/> </four> <five> <xsl:value-of select="results/count"/> <xsl:text> attempts made by </xsl:text> <xsl:value-of select="results/user"/> </five> <six><xsl:value-of select='results/message'/></six> </top>