Opened 18 years ago
Closed 18 years ago
#742 closed defect (invalid)
Parameters don't work with xsl:template tag
Reported by: | Owned by: | roadrunner | |
---|---|---|---|
Priority: | normal | Component: | XsltMacro |
Severity: | minor | Keywords: | |
Cc: | Trac Release: | 0.9 |
Description
With a parameter of xp_machineid in the macro command the following works almost. I am getting a dump of everything in the XML file before record $machineid and after $machineid. The transform is being applied ok to $machineid.
<xsl:template match="/systems/computer[@id=$machineid]">
If I take the attribute selector out of the template tag and move it down to a value-of tag, all works well.
<xsl:template match="/systems"> <td><xsl:value-of select="computer[@id=$machineid]/information/name"/></td>
I am very new to all of this, but according to all I have read this should work. Is this a bug somewhere?
Attachments (2)
Change History (8)
comment:1 Changed 18 years ago by
Owner: | changed from roadrunner to anonymous |
---|---|
Status: | new → assigned |
comment:2 Changed 18 years ago by
Owner: | changed from anonymous to roadrunner |
---|---|
Status: | assigned → new |
comment:3 Changed 18 years ago by
Status: | new → assigned |
---|
comment:4 Changed 18 years ago by
Thanks for taking a look. The macro is great by the way. Here are the files. I am probably missing something simple.
Changed 18 years ago by
Attachment: | asg_machine_summary.xsl added |
---|
XSL file using parameter from XSLT hack
comment:5 Changed 18 years ago by
The problem has to do with the default templates. XSL provides default templates that get applied when none of your supplied templates match. In the second case you're matching '/systems' and not calling <xsl:apply-templates> anywhere, so no default templates come into play. In the first case, however, what happens is that the processor first takes /systems, finds no template of yours and therefore applies the default templates, which in turn tell the processor to apply the templates on all children, i.e. all 'computer' nodes. Now, one of those nodes will match your template, and hence will be printed properly; but all other nodes won't, and hence will have the default templates applied to them (which end up printing the strings values of those nodes).
One way to prevent the other computer nodes from being processed by the default templates is to include an explicit (empty) template for them:
<xsl:template match="/systems/computer[not(@id=$machineid)]"/>
Another solution is to make sure the templates only get applied on the nodes you're interested in in the first place. E.g. by doing
<xsl:template match="/systems"> <xsl:apply-templates select="computer[@id=$machineid]"/> </xsl:template> <xsl:template match="computer"> <table> ... </xsl:template>
comment:6 Changed 18 years ago by
Resolution: | → invalid |
---|---|
Status: | assigned → closed |
Closing this because it's not a bug with the macro or even the xsl processor.
I'm not sure this is a problem with the macro. Can you attach the full xslt stylesheet and xml input doc?