if and count for xsl
Posted: Wed Aug 25, 2004 1:56 pm
hi to everyone,
i have got this xml:
<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSPY v2004 rel. 3 U (http://www.xmlspy.com) by MA (GE) -->
<!--Sample XML file generated by XMLSPY v2004 rel. 3 U (http://www.xmlspy.com)-->
<n:DepositoInsinuazioni xmlns:n="http://www.giustizia.it/Concorsuali/StatoPassivo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.giustizia.it/Concorsuali/StatoPassivo
D:\MINISTERO\Krakatoa\src\interop\xml\Insinuazioni\InsinuaETipi.xsd">
<n:Procedura n:Tribunale="0370060094" n:RuoloGenerale="215" n:Anno="2004" n:Sentenza="68" n:DataSentenza="2004-03-10"/>
<n:Insinuazione>
<n:Identificativo n:CodiceFiscale="VRDMRA59A25E379B"/>
<n:Mandato>
<n:Mandatario n:CodiceFiscale="01234567890"/>
<n:NumeroMandato>100</n:NumeroMandato>
<n:DataMandato>2004-04-02</n:DataMandato>
</n:Mandato>
</n:Insinuazione>
<n:Insinuazione>
<n:Identificativo n:CodiceFiscale="VRDMRA59A25E379B"/>
<n:NumeroInsinuazione/>
<n:Mandato>
<n:Mandatario n:CodiceFiscale="01234567890"/>
<n:NumeroMandato>100</n:NumeroMandato>
<n:DataMandato>2004-04-02</n:DataMandato>
</n:Mandato>
</n:Insinuazione>
</n:DepositoInsinuazioni>
I want insert a new element <n:NumeroInsinuazione/> like an ancestor of <n:Insinuazione> where this new element is not present already.
Whit the xsl below insert a new element into each node <n:Insinuazione>.
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/ | @* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="n:Insinuazione/n:Identificativo" xmlns:n="http://www.giustizia.it/Concorsuali/StatoPassivo">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
<xsl:element name="n:NumeroInsinuazione"/>
</xsl:template>
</xsl:stylesheet>
I tryed to modify this xsl adding a if (see below), but this dosen't work, becouse I think that the xpath into the if condition isn't correct.
How can insert the element <n:NumeroInsinuazione/> jast where I want?
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/ | @* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="n:Insinuazione/n:Identificativo" xmlns:n="http://www.giustizia.it/Concorsuali/StatoPassivo">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
<xsl:if test="count(/n:NumeroInsinuazione)=0">
<xsl:element name="n:NumeroInsinuazione"/>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
thanks
i have got this xml:
<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSPY v2004 rel. 3 U (http://www.xmlspy.com) by MA (GE) -->
<!--Sample XML file generated by XMLSPY v2004 rel. 3 U (http://www.xmlspy.com)-->
<n:DepositoInsinuazioni xmlns:n="http://www.giustizia.it/Concorsuali/StatoPassivo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.giustizia.it/Concorsuali/StatoPassivo
D:\MINISTERO\Krakatoa\src\interop\xml\Insinuazioni\InsinuaETipi.xsd">
<n:Procedura n:Tribunale="0370060094" n:RuoloGenerale="215" n:Anno="2004" n:Sentenza="68" n:DataSentenza="2004-03-10"/>
<n:Insinuazione>
<n:Identificativo n:CodiceFiscale="VRDMRA59A25E379B"/>
<n:Mandato>
<n:Mandatario n:CodiceFiscale="01234567890"/>
<n:NumeroMandato>100</n:NumeroMandato>
<n:DataMandato>2004-04-02</n:DataMandato>
</n:Mandato>
</n:Insinuazione>
<n:Insinuazione>
<n:Identificativo n:CodiceFiscale="VRDMRA59A25E379B"/>
<n:NumeroInsinuazione/>
<n:Mandato>
<n:Mandatario n:CodiceFiscale="01234567890"/>
<n:NumeroMandato>100</n:NumeroMandato>
<n:DataMandato>2004-04-02</n:DataMandato>
</n:Mandato>
</n:Insinuazione>
</n:DepositoInsinuazioni>
I want insert a new element <n:NumeroInsinuazione/> like an ancestor of <n:Insinuazione> where this new element is not present already.
Whit the xsl below insert a new element into each node <n:Insinuazione>.
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/ | @* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="n:Insinuazione/n:Identificativo" xmlns:n="http://www.giustizia.it/Concorsuali/StatoPassivo">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
<xsl:element name="n:NumeroInsinuazione"/>
</xsl:template>
</xsl:stylesheet>
I tryed to modify this xsl adding a if (see below), but this dosen't work, becouse I think that the xpath into the if condition isn't correct.
How can insert the element <n:NumeroInsinuazione/> jast where I want?
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/ | @* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="n:Insinuazione/n:Identificativo" xmlns:n="http://www.giustizia.it/Concorsuali/StatoPassivo">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
<xsl:if test="count(/n:NumeroInsinuazione)=0">
<xsl:element name="n:NumeroInsinuazione"/>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
thanks