Reputation: 733
I am trying to access a xsl template in a different xsl file from inside my template. The 2 templates are on different XSL files and that's the reason I need the document function. The templates also apply on different xml files.
My problem is how to call the second template from inside the first one. Sample of my code:
I am inside template Library:
<xsl:template match="Library">
<fo:table table-layout="fixed" width="160mm">
<fo:table-column column-width="80mm"/>
<fo:table-column column-width="80mm"/>
<fo:table-body>
<fo:table-row>
<xsl:for-each select="document(Library/@File)/Document/Books">
<xsl:apply-templates select="."/>
</xsl:for-each>
</fo:table-row>
<fo:table-body>
</fo:table>
</xsl:template>
and I am trying to access the template Books:
<xsl:template match="Books">
<fo:table-cell>
<fo:block font-family="arial" font-size="8pt" text-align="left">
<xsl:value-of select="substring(@IBAN,4)"/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block font-family="arial" font-size="8pt" text-align="left">
<xsl:value-of select="@date"/>
</fo:block>
</fo:table-cell>
</xsl:template>
The first argument inside the document function does not seem to be set correctly. Any thoughts on how should i rewrite it ? I couldn't find any issue in the forum having a similar problem. Any help would be appreciated, thanks
Upvotes: 1
Views: 427
Reputation: 111716
To bring a template in from another XSLT file, use xsl:import
or xsl:include
. Use xsl:document
when you want to apply XSLT templates to the XML found in the specified document in addition to the default input XML.
Unfortunately, you will not be able to use a variable in the path to the XSLT file because the path is resolved at compile-time.
If the path cannot be determined statically (possibly achieving the needed variation via a relative path specification), you might want to reconsider your overall organization. You could go so far as to compose your XSLT programatically before running it so as to be able to dynamically write the static @href, but do reconsider your overall solution architecture before going that far.
Upvotes: 1