insert a new element into a right position
Posted: Thu Sep 16, 2004 5:47 pm
hi,
I have written a xsl to transform a xml to another xml.
The xsl insert a new element if it isn't present in a node.
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="">
<xsl:template match="/ | @* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="c:Insinuazione xmlns:c="http://www.giustizia.it/Concorsuali/StatoPassivo">
<xsl:apply-templates select="c:Insinuazione/c:Identificativo"/>
<xsl:copy>
<xsl:if test="count(c:NumeroInsinuazione)=0">
<xsl:element name="NumeroInsinuazione"/>
</xsl:if>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:stylesheet>
The element inserted is "NumeroInsinuazione", but the xsl inserts it as first element of the node and I want to insert it as second (later the first element already present into the node).
Example:
Now I get:
...
<Insinuazione>
<NumeroInsinuazione/>
<Indentificativo/>
...
</Insinuazione>
I want get:
...
<Insinuazione>
<Indentificativo/>
<NumeroInsinuazione/>
...
</Insinuazione>
is it possible do it?
thanks
ciccio
I have written a xsl to transform a xml to another xml.
The xsl insert a new element if it isn't present in a node.
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="">
<xsl:template match="/ | @* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="c:Insinuazione xmlns:c="http://www.giustizia.it/Concorsuali/StatoPassivo">
<xsl:apply-templates select="c:Insinuazione/c:Identificativo"/>
<xsl:copy>
<xsl:if test="count(c:NumeroInsinuazione)=0">
<xsl:element name="NumeroInsinuazione"/>
</xsl:if>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:stylesheet>
The element inserted is "NumeroInsinuazione", but the xsl inserts it as first element of the node and I want to insert it as second (later the first element already present into the node).
Example:
Now I get:
...
<Insinuazione>
<NumeroInsinuazione/>
<Indentificativo/>
...
</Insinuazione>
I want get:
...
<Insinuazione>
<Indentificativo/>
<NumeroInsinuazione/>
...
</Insinuazione>
is it possible do it?
thanks
ciccio