XSLT Attribute-Set Dependency Report/Query

Viewed 23

We've got a number of directories, each containing several attribute-sets. Many of these attribute-sets use other attribute-sets. The attribute-set stylesheets are imported in a particular order to override same-named attribute-sets imported earlier. Since any attribute-set can use multiple attribute-sets (multiple inheritance), the problem fans out quickly. It's difficult to know without a lot of manual searching the answers to various questions, such as:

  1. Which attribute-sets could be affected by a change to a specific attribute-set, either directly directly or indirectly through multiple layers of use-attribute-sets? (looking down the "inheritance" tree for descendants)
  2. Which attribute-sets contribute to the definition of a given attribute-set? (looking upward for ancestors)
  3. What is the computed set of attributes and values from layers of "inheritance" for a given attribute-set, including showing the contributing file and attribute-set names?

Do any such tools exist? If not, since it's XML, is there an elegant way to use XSLT3, XQuery3, and XPath3.1 to address this need?

1 Answers

Good question. The XSLT import/override mechanism is very powerful, but if overused it can indeed be very hard to work out what's going on.

Does XsltExplorer (https://xslt.xmlexplorer.com) help at all? If not, you could try asking Norm for a new feature...

Or you could write your own tool. One of the benefits of XSLT using XML syntax is that it's very easy to write XSLT code that analyses (or modifies) XSLT code. IIRC, my book XSLT Programmer's Reference has an example that searches a stylesheet to see if there's a cycle in the attribute-set definitions, though it may only search within a single module.

Or you could write an extension to XsltExplorer yourself and contribute it to the project...

Another possibility, and I haven't really verified that this is feasible, is to look at the attribute sets in the output of Saxon's XSLT compiler - compile the stylesheet to a SEF file, and look inside it for the expanded versions. (There are actually two Saxon compilers you could try: the XJ compiler which is part of Saxon-EE (needs a license) produces a SEF file in XML format; the XX compiler in Saxon-JS runs on Node.js, is free, and produces a SEF file in JSON format).

Attribute sets are an interesting feature. I don't think I've ever used them in anger myself, and I very rarely encounter them in the wild. But people who do use them swear by them and tend to go overboard in exploiting their power.

Related