Given an XML like this:
<a id="1">
<b>
<code>42</code>
</b>
</a>
And the target being:
<request>
<aId>1</aId>
<bCode>42</bCode>
</request>
I can reach that using this XSLT:
<template match="/">
<element name="request">
<apply-templates/>
</element>
</template>
<template match="a">
<element name="aId"><value-of select="@id"/></element>
<apply-templates/>
</template>
<template match="b/code">
<element name="bCode"><value-of select="."/></element>
</template>
However, this also works if I swap <apply-templates/> with <next-match/>. Any advice on which to use when, when they both seem to work fine? Does next-match have additional effects which can mess things up if I add more stuff later for example?
Well in that case your use of
next-matchrelies on the built-in element template doingapply-templates(see http://www.w3.org/TR/xslt20/#built-in-rule). And once you added a template for elements e.g.the
next-matchwould no longer use the built-in template which does nothing butapply-templatesbut would choose above template which adds result nodes.So for your code I would continue to use
apply-templates.