- markup (52)
- xml (7)
- xslt (21)
- atom (8)
- overlapping markup (2)
- schema (9)
- creole (4)
- xforms (1)
- pipelines (7)
- coding (2)
- dtll (1)
- genealogy (3)
- gtd (1)
- hardware (1)
- legislation (1)
- ontologies (2)
- unicode (1)
- web (24)
- google (3)
- rdf (6)
- rest (3)
- wikis (1)
- work (1)
- xpath (1)
- xquery (1)
- xtech2008 (3)
- life (26)
- children (5)
- equality (6)
- environment (4)
- gadgets (5)
- software (3)
- xlinq (2)
- conferences (7)
- xtech (6)
- blog (7)
- drupal (3)
Re: Matching templates, named templates or for-each? My rules of
In XSLT 1.0, I think I’d do what you’ve done, except that I’d probably use a parameter in the base template, as in
and refer to
$sectionrather than the context node in the body of the template. Or, knowing me, and although I can’t justify it, I’d use a mode, and doThen, create a template for the specialisation that applies templates to that element in the same mode:
In XSLT 2.0, I’d create a function to test whether something was a section:
and use that function in the match pattern for my generic template:
Then, in the stylesheet for my specialisation, add
(ie register
<mystuff:supersection>as being a Docbook section).If I needed to do extra things to the
<mystuff:supersection>element, I can use<xsl:next-match>(or<xsl:apply-imports>) to get the basic result:In XSLT 2.0 Schema-Aware, you could use substitution groups to do the same kind of thing, even without using a full schema. But you would be limited to a single inheritance hierarchy, which might or might not fit your specialisations. User-defined functions like the above, on the other hand, can classify elements into groups in any way that you like.
The downside of this design is that it depends on you knowing, when you create the base stylesheet, what kind of specialisations you’re going to have. Plus it’s a lot more verbose than the method you describe.