add a new element into an xml file with the same namespace

Are you missing a feature? Request its implementation here.
Guest

add a new element into an xml file with the same namespace

Post by Guest »

hi,
I have a big problem and I hope that someone could help me.

if an element isn't present into the xml file, I want insert it.

The xsl to trasform the xml is:

<?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>
<xsl:if test="count(c:NumeroInsinuazione)=0">
<xsl:element name="NumeroInsinuazione"/>
</xsl:if>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:stylesheet>

if NumeroInsinuazione is not in the xml, the xsl trasfom it adding the element.
The problem is that I want that the new element takes the same namespace suffix of the source xml, otherwise I can't validate it.
Is it possible to do it?

best regards
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post by george »

Hi,

You can use

<xsl:element name="NumeroInsinuazione" namespace="http://www.giustizia.it/Concorsuali/StatoPassivo"/>

instead of:

<xsl:element name="NumeroInsinuazione"/>

Best Regards,
George
meciccio
Posts: 6
Joined: Wed Aug 11, 2004 6:00 pm

Post by meciccio »

hi george,
I was in holiday and now I started again with the same problem.
thanks for your help. I have tried your solution and works correctly and the validation finish fine, but I am using the xml that I have got from the transformation in a oracle XMLType to update the value of NumeroInsinuazione, so if the element is for example <n:NumeroInsinuazione> the update function of the xmltype finds the element, but if the element is <NumeroInsinuazione + namespace> the update function doesn't find the element and I can't assign a value to it.

If you know something to avoid this problem, please tell me.
In each case thanks for your help.

I hope my english is enough correct and unintelligible.

best regard
ciccio
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post by george »

Hi Ciccio,

You should obtain also the element in the correct namespace if c is mapped to the target namespace and you use:

<xsl:element name="c:NumeroInsinuazione"/>

Best Regards,
George
Post Reply