Ayrad
Ayrad

Reputation: 4056

problem with xsl apply-templates

It seems that my template is never called but the for loop works correctly.

It prints "test" exactly the number of times the "car" node exists but "doStuff" doesn't seem to be accessed and "test2" is never outputted. Any ideas?

<fo:table-body>
      <xsl:for-each select="car">
      test
  <xsl:apply-templates select="car" />
  </xsl:for-each>
</fo:table-body>

....

<xsl:template match="car">
<fo:table-row height="0.40cm">
test2
dostuff()....

Upvotes: 3

Views: 529

Answers (2)

Dathan
Dathan

Reputation: 7456

Within the for-each, "car" is the active node, and since by default the select attribute on apply-templates searches the descendants axis, it's trying to select "car" elements that are children of the active car element. Try

<xsl:apply-templates select="."/>

instead.

Upvotes: 4

Lucero
Lucero

Reputation: 60276

That's because you're trying to apply a nested car...

The for-each already changes the context, so that you have to apply the template on the current node:

<xsl:apply-templates select="."/>

Upvotes: 7

Related Questions