![]() |
| XPath Data Types Xsltp.pl Perl XSLT parser has no number type and string type. Strings and numbers are scalars. This is why the following declarations of the variable are all identical <xsl:variable name="var" select="'2'"/> <xsl:variable name="var" select="2"/> <xsl:variable name="var">2</xsl:variable> You may think about numbers of this processor as XSLT 1.0 strings, which are internally converted to numbers when this is necessary. XPath number(...) function returns NaN if a scalar is not a number. XPATH string(...) function does nothing with numbers. Boolean type is context dependent. This means that there are no boolean variables (if you define one with boolean expression it will be equal to scalar 1 or 0). However, when xsltp.pl XSLT parser sees a boolean expression the program processes it correctly and converts scalars and node-sets to boolean type. All predicates are evaluated as boolean expressions. Hence, element[$var] is a node-set consisting of all element children of the current node while element[$var=position()] is the second element child of the current node. Result tree fragment variable is always converted to a node-set consisting of just a root node. You can use step operators with result tree fragment variables. Here is an example. <xsl:variable name="time"><year>2003</year> <month>12</month>...</xsl:variable> Then expression string($time/month) is equal to 12. With global parameters var1 and var2 you can write name[$var1]/childname[$var2] for $var2 childname element of $var1 child name element of the current node provided that $var1 and $var2 are positive integers. Never use negative integers as element indexes. Declare the global parameter, which is passed to the stylesheet and is used as index, with type unsigned-int. Remark. Strictly speaking, XML has two data types: strings and nodes (data objects), while XPATH 1.0 has expression types and no data types. |