Variables may NOT be used within this expression (in template match)  
Author Message
DavidR100





PostPosted: XML and the .NET Framework, Variables may NOT be used within this expression (in template match) Top

I'm getting teh above error with the following error indication:

The following (from http://www.hide-link.com/ ) seems to indicate this should be possible:

I dont suppose the MS DOM is based on the Saxon processor

Consider the example below where a top-level variable (the only variables that can be referenced in template match expressions), parameterized from the command line, is used to match only those elements named by the operator invoking the stylesheet.

Note that while variables cannot be used as a node test in a location step, they can be used in a predicate.

Interestingly, Saxon gives an error on this stylesheet that works fine with XT. I think Saxon is in error here because XSLT [5] allows predicates in match patterns.

< xml version="1.0" >
:
<xsl:param name="which"/> <!--require the operator to specify--> :
<!--only interested in the ones indicated by the operator--> <xsl:template match="*[name(.)=$which]" priority="1"> <xsl:value-of select="."/> </xsl:template> <!--eat all other output--> <xsl:template match="*|text()" priority="0"/> </xsl:stylesheet>



.NET Development3  
 
 
Dimitre_Novatchev





PostPosted: XML and the .NET Framework, Variables may NOT be used within this expression (in template match) Top

The error message is correct.

In XSLT 1.0 variable references cannot be used within a match pattern, because this may lead to circular references -- such as when a global xsl:variable has in its body an xsl:apply-templates instruction, which could select for execution a template, which references the same xsl:variable.

Cheers,
Dimitre Novatchev


 
 
DavidR100





PostPosted: XML and the .NET Framework, Variables may NOT be used within this expression (in template match) Top

any alternative solutions then

I just want to only process nodes that match. I would guess that doing so in a xsl:for-each mighgt do the trick, I could just apply templates from in there anyway



 
 
Dimitre_Novatchev





PostPosted: XML and the .NET Framework, Variables may NOT be used within this expression (in template match) Top

> Any other alternatives then

That's easy:

<xsl:template match="*" priority="1">

<xsl:if test="name(.)=$which">
<xsl:value-of select="."/>
</xsl:if>
</xsl:template>

Cheers,
Dimitre Novatchev