I had the following definition for a variable
<xsl:variable name="DataType" select="@DataType"/>
Which works just fine…
Now I want to set its value using a condition like this
<xsl:variable name="DataTypeOverrideType" select="$DataSource/@DataTypeOverrideType"/>
<xsl:variable name="DataType">
<xsl:choose>
<xsl:when test="$ObeyTypeOverride and $DataTypeOverride = 1">
<xsl:value-of select="$DataTypeOverrideType"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@DataType"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
But i;m getting the following error :
reference to variable or parameter ‘DataType’ must evaluate to a node list
I also tried the simplest example, like this
<xsl:variable name="DataType">
<xsl:value-of select="@DataType"/>
</xsl:variable>
but I keep on getting the error 😐
After the changes i did to the way of defining the variable i’m trying to use it , like this
<xsl:when test="$DataType = 'ReachEdit'">
and like this
<xsl:when test="$DataType = 9">
any ideas on how can i solve this issue?
Thanks ahead!
This isuue is due to the fact that you define a variable having an RTF (Result-Tree-Fragment) type. In order to use the contents of this variable as a regular tree, you must first convert it to a regular tree using an
xxx:node-set()extension function, where the prefix"xxx:"must be bound to an implementation (vendor-provided) namespace.Also, the provided code snippet doesn’t make sense:
In both cases above the same value is output!
My guess is that you want something like this:
In such a case it is possible in XPath 1.0 to define the variable without creating an RTF:
Update: The question is now updated with corrected snippet and example of the actual uses of the variable, that cause the error message.
As the variable is used as atomic value, the error message shouldn’t be raised if the following XPath expressions are used:
and