insert a new element into a right position
Are you missing a feature? Request its implementation here.
insert a new element into a right position
Post by Guest »
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
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Hi Ciccio,
You are still fighting the same problem
.
Here it is:
Best Regards,
George
You are still fighting the same problem

Here it is:
Code: Select all
<?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:copy>
<!--Copy the attributes -->
<xsl:apply-templates select="@*"/>
<!-- Copy the first element -->
<xsl:apply-templates select="c:Identificativo"/>
<!-- Generate c:NumeroInsinuazione if necessary-->
<xsl:if test="count(c:NumeroInsinuazione)=0">
<xsl:element name="c:NumeroInsinuazione"/>
</xsl:if>
<!-- Copy everything except the first element c:Identificativo -->
<xsl:apply-templates select="node()[not(self::c:Identificativo)]"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
George
-
- Posts: 6
- Joined: Wed Aug 11, 2004 6:00 pm
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service