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
- 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
My tactics of debugging these cases include
Continue reading »