I want to add a couple of elements at the end of an XML document, right before the closing of the root node, and I'm using an XSL to do the transformation.
The source XML can contain any node, subnode, etc, that doesn't matter. Everything in it should be copied to the transformed document, plus some other elements have to be added.
I'm totally new to XSL, XSLT and XPath, so I'm undoubtedly doing mistakes.
All my XSL's are like this:
<xsl:stylesheet xmlns:xsl="http://ift.tt/tCZ8VR" version="1.0">
<xsl:output method="xml" encoding="UTF-8" omit-xml-declaration="yes" />
<!-- tried directives -->
</xsl:stylesheet>
This is what I found and tried, but with no success.
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
<my-el></my-el>
</xsl:template>
I've read that's the identity template, so I thought I'd use it to copy everything plus an additional element; but this adds <my-el></my-el> inside each element of the source document.
After reading up a little of w3schools tutorials about XSLT and XPath, I tried with:
<xsl:template match="/">
<xsl:copy-of select="."></xsl:copy-of>
<my-elem />
</xsl:template>
But it adds <my-elem /> after the closing tag of the root element.
Can you help me out?
Background: I'm playing with the xml-maven-plugin to add some configuration to a web application web.xmlfile, triggered by a profile. I want that all of the existing XML in the file be copied to the output document, plus I want to add some (static will be enough for now) elements to it.
Here's the source web.xml file:
<web-app xmlns="http://ift.tt/nSRXKP" xmlns:xsi="http://ift.tt/ra1lAU"
xsi:schemaLocation="http://ift.tt/nSRXKP http://ift.tt/1eWqHMP"
version="3.0">
<display-name>My Project</display-name>
<welcome-file-list>
index.jsp
</welcome-file-list>
</web-app>
I want to achieve something like what's been asked in this question, but the new nodes have to be added to the root element (i.e. see a comment to that question answer).
No comments:
Post a Comment