Re: [xsl] Copy-per-default

Subject: Re: [xsl] Copy-per-default
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Wed, 20 Apr 2011 17:57:38 +0200
Fredrik Bengtsson wrote:

<xsl:template match="/d:book">
   <!-- ignoring root, page-sequence etc for brevity -->
   <xsl:apply-templates />
</xsl:template>

<xsl:template match="d:chapter">
   <xsl:apply-templates />
</xsl:template>

<xsl:template match="d:chapter/d:title">
   <fo:block>  ... ...</fo:block>
</xsl:template>


Then for some reason the titleabbrev appears in the output even though I have not made any rule explicitly matching it. It is caught along with the title inside the apply-templates under d:chapter. I thought that this would not happen, unless I really added a matching template of some sort, for example an identity transform.

Well in your template for chapter you do apply-templates meaning you process all child nodes. Then there is a built-in template that does the same for any element nodes not having a template in your stylesheet and there is a built-in template for text nodes that does xsl:value-of, thus the contents of the titleabbrev is copied to the output.


You can remedy this by either only selecting the title element with your apply-templates in the chapter template

<xsl:template match="d:chapter">
  <xsl:apply-templates select="d:title"/>
</xsl:template>

or by suppressing text output with

<xsl:template match="text()"/>


--


	Martin Honnen
	http://msmvps.com/blogs/martin_honnen/

Current Thread