Modify

Opened 18 years ago

Closed 18 years ago

#742 closed defect (invalid)

Parameters don't work with xsl:template tag

Reported by: jcarter@… 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)

asg_systems.xml (35.5 KB) - added by jcarter@… 18 years ago.
Computer Systems Records in XML
asg_machine_summary.xsl (1.1 KB) - added by jcarter@… 18 years ago.
XSL file using parameter from XSLT hack

Download all attachments as: .zip

Change History (8)

comment:1 Changed 18 years ago by roadrunner

Owner: changed from roadrunner to anonymous
Status: newassigned

I'm not sure this is a problem with the macro. Can you attach the full xslt stylesheet and xml input doc?

comment:2 Changed 18 years ago by roadrunner

Owner: changed from anonymous to roadrunner
Status: assignednew

comment:3 Changed 18 years ago by roadrunner

Status: newassigned

comment:4 Changed 18 years ago by jcarter@…

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 jcarter@…

Attachment: asg_systems.xml added

Computer Systems Records in XML

Changed 18 years ago by jcarter@…

Attachment: asg_machine_summary.xsl added

XSL file using parameter from XSLT hack

comment:5 Changed 18 years ago by roadrunner

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 roadrunner

Resolution: invalid
Status: assignedclosed

Closing this because it's not a bug with the macro or even the xsl processor.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain roadrunner.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.