I’ve got this issue.
A template called “checkbox” that’s called from while inside a table HTML element and also outside of it.
To solve an issue, I’ve added <td> tags to “checkbox” input control.
Here’s what I’d like to do to but I’m not sure if it’s possible or not.
When I hit my “row” (part of the custom table markup) template, I would set some variable or pass some parameter, that for each template applied afterwards, would know it was in a “row” and do something special based on this information. I know I can’t add parameters to apply-templates. I may be able to add a row “mode” but I can’t make changes to each template and have one copy with the mod parameter and one without.
Thanks for any suggestions. I know the ideal solution would to be to make changes to the XML but I’m not sure if I can do that as this point. That’s a “content” issue. 😛
Thanks!
Addendum:
I’m going to try to better explain my issue.
I have this template called “checkbox”. Sometimes I need a tag surrounding the call that renders the checkbox, sometimes I do not. The times I do the “checkbox” template are when its parents are called by a “row” template’s call to apply-templates (this translates to a , thus the need for the for the checkbox forum control).
The problem is I need to be able to reuse the checkbox template in both cases: 1) When it’s not being called by a row template and when it IS being called by a row template.
I hope this is clearer.
To begin with, parameters can be passed to templates that are selected for processing by an
<xsl:apply-templates>instruction. Do read about<xsl:with-param>.However, passing such a parameter isn’t usually needed. Here is an example:
If a template matches a specific (current) node and it must act in a special way depending whether this node is within a table row, then it is a matter of a simple check:
parent::trselects the parent node only if it is a
tr.ancestor::trselects all ancestor
trnodes.In case the first or the second XPath expressions above selects a non-empty node-set, then (respectively), the parent of the current node is a
tr, or the current node is within sometr.So, you may use an
<xsl:when>to test this.Here is how a complete solution may look like:
when this transformation is applied on the following XML document:
the wanted, correct result is produced:
Very often conditional instructions can be completely eliminated by specifying specific templates with predicates in the match pattern. If you provide the necessary relevant information, people might be able to publish an elegant solution.