Apr 252011

XSLT/XPath 2.0/3.0 are powerful technologies. But sometimes they’ll drive you nuts. A large share of issues falls into the category of “why doesn’t my template match?” The reasons are manifold. Here are some typical traps:

  • not including the namespace prefix
  • typo in the namespace URI
  • processing the document in a different mode than the template is supposed to match in. A very subtle example, accidentally closing the xsl:template start tag, cutting off the existing mode declaration – this actually happened to me:
<xsl:template match="HyperlinkTextSource[…]">
    mode="idml2xml:ConsolidateParagraphStyleRanges-remove-empty" priority="4">
  • other typos (in predicates, element names, modes)
  • skipping intermediate elements, e.g., formulating predicates for <td>s when the template is supposed to match <tr>
  • other templates have higher priority
  • import precedence: this template is an imported one, and there is a matching template of whatever priority in the importing stylesheet, or in a template imported after the template in question
  • logical misconceptions in the predicates
  • if the template is supposed to match a result of a previous transformation: the output of the previous tranformation is not as expected
  • processing some surrounding element with xsl:copy-of instead of xsl:apply-templates
  • not looking at the actual output document, or looking at another part of the document, while your template indeed matched (thanks, @fbuehring)

My tactics of debugging these cases include

Continue reading »

Nov 172010

Suppose you imported XML data into an InDesign document. Suppose that the layout should convey the markup’s semantics: keywords in italics, proper names in small caps, block quotes indented etc.

There are several ways how to map the markup to the layout. But it is important to know: no matter how you’ve mapped it, once the mapping has taken place, markup and layout information may evolve in totally different directions. And this is dangerous. For real-world XML document types and real-world typesetting, mapping is a one-way street, leading from markup to layout, and not the other way round, as we’ll see later. If you trust that after carrying out author corrections, everything that looks like a keyword will be a keyword in the exported XML, you may be proven wrong later. Or the two paragraphs that you see in InDesign are still a single one in XML, because it has been split only visually after import and the markup hasn’t been updated accordingly.

Continue reading »