parameters in a search with match

I

Iain

I've got some XLST which extracts some stuff from a config file. it works
nicely. Now I want to make it work with a parameter

My original attempt looked like (fragment)

<xsl:param name="StyleName" />

<xsl:template match="/Vendor/Style[@Name=$StyleName]" >

And failed. (replace $StyleName in the above with a real style name and it
works correctly). Eventually, I came up with this ...

<xsl:param name="StyleName" />

<xsl:template match="/Vendor" >

<xsl:for-each select="Style[@Name=$StyleName]" >

Which works also. But WHY won't it work with the match?

Iain

PS. I claim no skill in these areas - xslt/xpath and their friends are NOT
pellicidly clear.
 
D

Dimitre Novatchev

A match pattern cannot have a variable/parameter references in XSLT 1.0
because this might lead to circular definitions (the referenced xsl:variable
may have xsl:apply-templates in its body and the template that references
this variable may be applied ...)

The workaround is the following:

Instead of:

match = "aPatternWithVariableReference"

use:

<xsl:template match="correctPattern">
<xsl:if test="someConditionWithTheVariableReference">
<!-- The whole processing goes only here -->
</xsl:if>
</xsl:template>

As you can see, this would be equivalent to:

<xsl:template
match="correctPattern[someConditionWithTheVariableReference]">
<!-- Whatever processing should be performed -->
</xsl:template>

if the latter were allowed.

=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
 
I

Iain

Thanks!

Iain
Dimitre Novatchev said:
A match pattern cannot have a variable/parameter references in XSLT 1.0
because this might lead to circular definitions (the referenced xsl:variable
may have xsl:apply-templates in its body and the template that references
this variable may be applied ...)

The workaround is the following:

Instead of:

match = "aPatternWithVariableReference"

use:

<xsl:template match="correctPattern">
<xsl:if test="someConditionWithTheVariableReference">
<!-- The whole processing goes only here -->
</xsl:if>
</xsl:template>

As you can see, this would be equivalent to:

<xsl:template
match="correctPattern[someConditionWithTheVariableReference]">
<!-- Whatever processing should be performed -->
</xsl:template>

if the latter were allowed.

=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL


Iain said:
I've got some XLST which extracts some stuff from a config file. it works
nicely. Now I want to make it work with a parameter

My original attempt looked like (fragment)

<xsl:param name="StyleName" />

<xsl:template match="/Vendor/Style[@Name=$StyleName]" >

And failed. (replace $StyleName in the above with a real style name and it
works correctly). Eventually, I came up with this ...

<xsl:param name="StyleName" />

<xsl:template match="/Vendor" >

<xsl:for-each select="Style[@Name=$StyleName]" >

Which works also. But WHY won't it work with the match?

Iain

PS. I claim no skill in these areas - xslt/xpath and their friends are NOT
pellicidly clear.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top