I'm a newbie at XSL/XSLT. I'm trying to add a new element (datasources) to all users elements of this xml:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<users>
<user id="1">
<repo>r1</repo>
<home>h1</home>
</user>
<user id="2">
<repo>r2</repo>
<home>h2</home>
</user>
<user id="3">
<repo>r3</repo>
<home>h3</home>
</user>
<user id="4">
<repo>r4</repo>
<home>h4</home>
</user>
<user id="5">
<repo>r5</repo>
<home>h5</home>
</user>
</users>
I'm using this XSL script:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes" cdata-section-elements="configXml"/>
<!-- Copy everything -->
<xsl:template match="node()">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="/users/user[*]">
<xsl:copy>
<xsl:apply-templates/>
<xsl:element name="datasources"></xsl:element>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
The problem is that in the final result the id of all users disappear:
<users>
<user>
<repo>r1</repo>
<home>h1</home>
<datasources/>
</user>
<user>
<repo>r2</repo>
<home>h2</home>
<datasources/>
</user>
<user>
<repo>r3</repo>
<home>h3</home>
<datasources/>
</user>
<user>
<repo>r4</repo>
<home>h4</home>
<datasources/>
</user>
<user>
<repo>r5</repo>
<home>h5</home>
<datasources/>
</user>
How can I keep the users id in the output?