if and count for xsl
Having trouble installing Oxygen? Got a bug to report? Post it all here.
if and count for xsl
Post by Guest »
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
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Hi,
I'm not sure I understand your question exactly, anyway if you want to add the n:NumeroInsinuazione element inside n:Insinuazione if that is not present already then the following stylesheet should do it.
Best Regards,
George
I'm not sure I understand your question exactly, anyway if you want to add the n:NumeroInsinuazione element inside n:Insinuazione if that is not present already then the following stylesheet should do it.
Code: Select all
<?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" xmlns:n="http://www.giustizia.it/Concorsuali/StatoPassivo">
<xsl:copy>
<xsl:if test="count(n:NumeroInsinuazione)=0">
<xsl:element name="n:NumeroInsinuazione"/>
</xsl:if>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
George
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
A small update: if you have attributes on the n:Insinuazione element then the stylsheet should be changed as follows to copy first the attributes then check and add the n:NumeroInsinuazione element and then copy the rest of the n:Insinuazione element content:
Best Regards,
George
Code: Select all
<?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" xmlns:n="http://www.giustizia.it/Concorsuali/StatoPassivo">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:if test="count(n:NumeroInsinuazione)=0">
<xsl:element name="n:NumeroInsinuazione"/>
</xsl:if>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
George
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ Artificial Intelligence (AI Positron Assistant add-on)
- ↳ 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