variable in template match
This is an open discussion with 4 replies, filed under Troubleshooting.
Search
First look through:
<xsl:apply-templates match="talen/item[@handle = $current-language]/stappen/item" />
The match
attribute is incorrect. It should say select
.
And change:
<xsl:template match="talen/item[@handle=$current-language]/stappen/item"> <h4><xsl:value-of select="title" /></h4> </xsl:template>
So that it does not include the predicate:
<xsl:template match="item"> <h4><xsl:value-of select="title" /></h4> </xsl:template>
Variables cannot be used in the value of a match
attribute.
So, you have two errors here. A typo and your use of a variable in the match
attribute. You don't need the predicate in both places anyways, in this case it must and is only necessary to have it in the select
attribute of the <xsl:apply-templates />
element.
Hope that helps!
Ah, that's great Lewis. Awesome response! Stupid I have completely overlooked the match in the apply-templates tag :S.
And about the second error. Ok, this makes me understand the selections process a little better. The template goes for any item, and I can apply it contextually, I think ;).
If you're worried about matching unexpectedly then you have the mode attribute for templates to help. Also remember that match attributes work on a specificity basis in a very similar way to css selectors.
Stupid I have completely overlooked the match in the apply-templates tag :S.
It happens... but if it becomes routine we will commence flogging with wet noodles :)
And about the second error. Ok, this makes me understand the selections process a little better. The template goes for any item, and I can apply it contextually, I think ;).
Correct. Check out the mode
and priority
attributes to learn how you can get fancy.
Create an account or sign in to comment.
Hi All,
I'm still learning, so this may be a trivial questoin. Yet, the answer isn't easy to find.
I want to use a variable inside a template match attribute, but this gives me an error. I'm not sure how else to achieve this:
With this xslt:
Gives me the following error: XSLTProcessor::importStylesheet(): Undefined variable Failed to compile predicate
The $current-language variable is working fine, but can't be processed when it's used in the match attribute? How can I overcome this problem?
EDIT I have used this now:
SELECTIE MENU
But i'm still wondering about the how and why about my question.