Duplicated XSLT Templates with Enabled

I am having a problem with enabling 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 an include statement to b and c, I get a duplicate of the template error in VS2008:

The named template 'MyTemplate' does not exist. 

and when I try to get to a web page using these XSLTs, I get an error message and they do not 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 am referring to does not exist:

 'MyTemplate' is a duplicate template name. 

What would be the proper way to include this include tree? Or maybe this is just a VS2008 problem?

I could exclude d.xslt and add this template to b and c, but it's easier to manage if the template is in the same place.

  • edited: Added actual error text VS2008.
+4
source share
3 answers

Using xsl:include is the same as inserting all of them into one giant file, which will also give you the same error in the templates.

Use xsl:import instead of xsl:include .
It overlays / combines all the patterns to give you a super set. The last template in the import chain will β€œwin” instead of giving you a recurring definition error, since it will have a higher priority.

  • Have a.xslt xsl:import b.xslt and c.xslt.
  • Have b.xslt and c.xslt xsl:include or xsl:import d.xslt.

Personally, I usually use xsl:import over xsl:include .

The only real drawback of xsl:import is that you can accidentally override the template further in the import chain and not know it (because you will not get the same compilation error as with xsl:include ). It may happen that the XSLT processor needs to β€œthink a little” about the import chain, but I have not found that this is a problem.

+10
source

IDEs such as VS2008 tend to believe when you edit a stylesheet document, which should be complete, that is, along with things that include / import, all names should be resolved. This is actually not the case with the XSLT language; when A turns on B, it is entirely legal for components in B to refer to components in A, although B does not include A. I believe that oXygen has a switch somewhere that allows you to control this. XSLT allows cyclic inclusion, but can cause problems with some processors.

+1
source

From http://www.w3.org/TR/xslt#named-templates

This is a mistake if the style sheet contains more than one template with the same name and import precedence .

It also shows that the xsl:import mechanism is better than the inclusion (in most cases), and it should be considered as an inheritance mechanism between transforms.

0
source

Source: https://habr.com/ru/post/1340360/


All Articles