Modify

Opened 8 years ago

Closed 8 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@… 8 years ago.
Computer Systems Records in XML
asg_machine_summary.xsl (1.1 KB) - added by jcarter@… 8 years ago.
XSL file using parameter from XSLT hack

Download all attachments as: .zip

Change History (8)

comment:1 Changed 8 years ago by roadrunner

  • Owner changed from roadrunner to anonymous
  • Status changed from new to assigned

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 8 years ago by roadrunner

  • Owner changed from anonymous to roadrunner
  • Status changed from assigned to new

comment:3 Changed 8 years ago by roadrunner

  • Status changed from new to assigned

comment:4 Changed 8 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 8 years ago by jcarter@…

Computer Systems Records in XML

Changed 8 years ago by jcarter@…

XSL file using parameter from XSLT hack

comment:5 Changed 8 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 8 years ago by roadrunner

  • Resolution set to invalid
  • Status changed from assigned to closed

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

Add Comment

Modify Ticket

Action
as closed .
as The resolution will be set. Next status will be 'closed'.
to The owner will be changed from roadrunner. Next status will be 'closed'.
The resolution will be deleted. Next status will be 'reopened'.
Author


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

 
Note: See TracTickets for help on using tickets.