I'm having a problem with including xslt templates.
I have a.xslt which includes b.xslt and c.xslt.
b and c both require a template located in d.xslt. If I add the include statement in b and c, I get a duplicate template error in VS2008:
The named template 'MyTemplate' does not exist.
and when I try to hit the web page that uses these XSLTs I get an error and they don't display correctly.
If I include d.xslt in a.xslt it will display correctly, but I get an error in b and c stating that the template I'm referencing doesn't exist:
'MyTemplate' is a duplicate template name.
What would be the correct way to have this kind of include tree? Or maybe it's just a VS2008 problem?
I could eliminate d.xslt and add that template to both b and c, but it's easier to manage if the template is in one place.
Using xsl:include
is the same as pasting them all in one giant file, which would also give you the same duplicate template errors.
Use xsl:import
instead of xsl:include
.
It will overlay/merge all of the templates to give you a super-set. The last template in the import chain will "win" instead of giving you a duplicate definition error, as it will have higher precedence.
xsl:import
b.xslt and c.xslt. xsl:include
or xsl:import
d.xslt.Personally, I tend to always use xsl:import
over xsl:include
.
The only real downside of xsl:import
is that you might accidentally override a template further down in the import chain and not know it(because you won't get the same compilation error that you would with xsl:include
). There might be a slight performance hit, since the XSLT processor has to "think" a little more about the import chain, but I haven't found that to be a problem.
IDEs such as VS2008 tend to believe when you are editing a stylesheet document that it must be complete, that is, taken together with the things it includes/imports, all names must resolve. In fact this is not the case according to the XSLT language; when A includes B it's quite legal for components in B to refer to components in A even though B does not include A. I believe oXygen has a switch somewhere that allows you to control this. XSLT allows cyclic includes, but they can cause problems with some processors.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With