Because the generated fragment is not a valid XML file ( it's a fragment after all ), it is not possible to use XSLT directly. On the other hand you don't have to. Here is a simple trick that will give you exactly what you need.
In your web.xml file insert XML comment <!-- @JSPS_MAP@ -->
between <servlet>
and <servlet-mapping>
elements, e.g.
<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>my.servlets.MyServlet</servlet-class>
<servlet>
<!-- @JSPS_MAP@ -->
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/my-servlet</url-pattern>
</servlet-mapping>
Then use a token filter to replace @JSPS_MAP@
tag with generated content.
<loadfile
property="generated.web.xml.fragment"
srcFile="${generated.fragment.file}"
/>
<copy file="${orig-web-content.dir}/WEB-INF/web.xml"
toFile="${generated-web-content.dir}/WEB-INF/web.xml"
>
<filterset>
<filter token="JSPS_MAP"
value=" --> ${generated.web.xml.fragment} <!-- "
/>
</filterset>
</copy>
This approach has an advantage that the original web.xml file is completely valid (a tag is hidden in the comment), but gives you total control of where and when the generated fragment will be inserted.
So for DEV build, just copy ${orig-web-content.dir}/WEB-INF/web.xml
to ${generated-web-content.dir}/WEB-INF/web.xml
without filtering.