0
votes

I'm trying to modify an existing XSLT to tailor it to my needs but wanted to understand the correct application of xsl:apply-templates to process additional tags.

Given the below existing code. I am trying to understand a few things firstly.

  1. <xsl:apply-templates/> with no select statement. So from the documents it says that this element applies a template to the current element OR to the current element's child nodes. So does this mean that for matches to tabelcell, then this template will only be applied to itself (and to children only if there were select statements to process those children)?

  2. Does the placement of in the sample code make a difference if it was after the end </td> tag instead of inside?

  3. If the sample code below did NOT have the line <xsl:apply-templates/> then will this mean nothing will happen on matches to tabelcell?

    <xsl:template match="tablecell"> <td valign="top"> Removed content for simplicity <xsl:apply-templates/> </td> </xsl:template>

  4. If there were children of <tabelcell> like <par> or <pardef> how would I need to modify the above code to incorporate such processing considering it already has an <xsl:apply-templates/> within the <td> elements? e.g. if I wanted to add <xsl:apply-templates select="par" />

I'm only new to XSLT and so far have been getting away with putting simply xsl:apply-templates elements with select statements within xsl:template tags until now.

If someone could help clarify my understanding of the behaviour and use of the xsl:apply-templates by answering my questions above that would be awesome.

Cheers,

1

1 Answers

1
votes
  1. So from the documents it says that this element applies a template to the current element OR to the current element's child nodes.

    I don't know where you've read this. It is not true. Here's what the specs say:

    In the absence of a select attribute, the xsl:apply-templates instruction processes all of the children of the current node, including text nodes.

  2. Yes, it makes a difference. The way you have it now, the result of applying the templates will be placed inside the td element. If you move the xsl:apply-templates instruction outside the td element, then that's where the result will end up in the output.

  3. No. The td element would still be created. It would just be empty (or more precisely, it would still contain whatever was in the "content removed for simplicity" part).

  4. This question is not clear. As explained in #1 above, all children of tablecell will be processed. If you add another instruction to <xsl:apply-templates select="par" />, then the par elements will be processed twice.