Reputation: 213
I am new to XSL-FO and have a very basic question, the following are xsl and xml files.
I expect "xxx" to be outputted for every xml node "inhouse" (template match).
But I am not getting it.
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="CustomerData">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="simple" page-height="29.7cm" page-width="21.0cm" margin-left="1.5cm" margin-right="1.5cm" margin-top="0cm">
<fo:region-body margin-top="3cm"/>
<fo:region-before extent="0cm"/>
<fo:region-after extent="0cm"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="simple">
<fo:flow flow-name="xsl-region-body">
<fo:block font-family="Arial" font-size="8.5pt" font-weight="normal">
abc
</fo:block>
<xsl:template match="inhouse">
<fo:block color="#053679">
xxx
</fo:block>
</xsl:template>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<CustomerData>
<inhouse>
<customerList>
<customer>
<name>Tom</name>
</customer>
</customerList>
</inhouse>
</CustomerData>
Upvotes: 2
Views: 1250
Reputation: 70618
The issue here is that you have a template match for inhouse within your template match for CustomerData
<xsl:template match="CustomerData">
...
<xsl:template match="inhouse">
....
</xsl:template>
....
</xsl:template>
You are not allowed to nest templates in this way. What you need to do is move your inhouse template out of the current template, but instead tell the XSLT processor to start looking for other templates at that point with xsl:apply-templates. Something like this structure
<xsl:template match="CustomerData">
...
<xsl:apply-templates select="inhouse" />
...
</xsl:template>
<xsl:template match="inhouse">
....
</xsl:template>
In fact, it could be slightly better to replace <xsl:apply-templates select="inhouse" />
with just <xsl:apply-templates />
as this would handle the case where you have other elements other than inhouse you wanted to match.
Try this XSLT
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="CustomerData">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="simple" page-height="29.7cm" page-width="21.0cm" margin-left="1.5cm" margin-right="1.5cm" margin-top="0cm">
<fo:region-body margin-top="3cm"/>
<fo:region-before extent="0cm"/>
<fo:region-after extent="0cm"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="simple">
<fo:flow flow-name="xsl-region-body">
<fo:block font-family="Arial" font-size="8.5pt" font-weight="normal">
abc
</fo:block>
<xsl:apply-templates />
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
<xsl:template match="inhouse">
<fo:block color="#053679">
xxx
</fo:block>
</xsl:template>
</xsl:stylesheet>
Upvotes: 1