I have a code generating XSL that includes several XSL files. The files are included in order to call templates. There can be the case when one of the files that I need to include does not exist in my file. I could create a dummy file with the same name and an empty template when the original file is missing but I would get a duplicate error when the original file exists.
Bellow is an example:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:date="java.util.Date"
xmlns:vector="java.util.Vector"
xmlns:math="java.lang.Math"
xmlns:int="java.lang.Integer"
xmlns:saxon="http://saxon.sf.net/"
extension-element-prefixes="date vector math int saxon">
<xsl:include href="file_for_template1.xsl"/> <!-- MIGHT NOT EXIST -->
<xsl:include href="file_for_template2.xsl"/> <!-- MIGHT NOT EXIST -->
<xsl:include href="file_for_template3.xsl"/> <!-- MIGHT NOT EXIST -->
<xsl:output method="xml"
version="1.0"
encoding="UTF-8"
indent="yes"/>
<xsl:variable name="path"
select="concat(base-uri(//Test),'.temp')"/>
<xsl:template match="/">
<xsl:result-document href="file:/{$path}" method="xml">
<!-- create the root node -->
<TEST_GENERATION xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="test.xsd">
<xsl:element name="TEST_ELEMENT">
<!-- SHOULD NOT BE CALLED IF THE FILE DOES NOT EXIST -->
<xsl:call-template name="template1Call"/>
<!-- SHOULD NOT BE CALLED IF THE FILE DOES NOT EXIST -->
<xsl:call-template name="template2Call"/>
<!-- SHOULD NOT BE CALLED IF THE FILE DOES NOT EXIST -->
<xsl:call-template name="template3Call"/>
</xsl:element>
<!-- end of root node -->
</TEST_GENERATION>
<!-- end of document -->
</xsl:result-document>
</xsl:template>