Hi!
I have the next XML:
<?xml version="1.0" encoding="ISO-8859-1"?>
<Registos>
<Registo>
<a>aaa</a>
<b>bbb</a>
<value>2592.19</value>
<detail>
<date>2003-11-20</date>
<value>13196.72</value>
</detail>
<detail>
<date>2003-11-20</date>
<value>13196.72</value>
</detail>
</Registo>
<Registo>
<a>aaa</a>
<b>bbb</a>
<value>0.00</value>
<detail>
<date>2003-11-20</date>
<value>13196.72</value>
</detail>
</Registo>
</Registos>
In the end I want the next XML.. The rules are:
* if value of tag "value" in "Registo" element is equal to zero then that tag
(<value>) must disappear
* all tag <detail> must have an atribute "num" that is an unique incremental ID.
<?xml version="1.0" encoding="ISO-8859-1"?>
<Registos>
<Registo>
<a>aaa</a>
<b>bbb</a>
<value>2592.19</value>
<detail num="1">
<date>2003-11-20</date>
<value>13196.72</value>
</detail>
<detail num="2">
<date>2003-11-20</date>
<value>13196.72</value>
</detail>
</Registo>
<Registo>
<a>aaa</a>
<b>bbb</a>
<detail num="3">
<date>2003-11-20</date>
<value>13196.72</value>
</detail>
</Registo>
</Registos>
I implements the follow XSL:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<Registos>
<xsl:for-each select=".//Registo">
<Registo>
<xsl:for-each select="*[name(.)!='detail']">
<xsl:if test="name(.)!='value'">
<xsl:copy-of select="."/>
</xsl:if>
<xsl:if test="name(.)='value' and
number(.)!=0">
<xsl:copy-of select="."/>
</xsl:if>
</xsl:for-each>
<xsl:for-each select="*[name(.)='detail']">
<detail>
<xsl:attribute name="num">
<xsl:value-of
select="count(preceding::*[name(.)='detail'])+1"/>
</xsl:attribute>
<xsl:for-each select="*">
<xsl:copy-of
select="."/>
</xsl:for-each>
</detail>
</xsl:for-each>
</Registo>
</xsl:for-each>
</Registos>
</xsl:template>
</xsl:stylesheet>
Although it's work, it's to slow! Can you help me to performance this xsl?
Tks :)
Hélder Sousa
Esta mensagem contém informação abrangida por sigilo ou confidencial. Caso
tenha recebido esta mensagem indevidamente, queira informar de imediato o
remetente e proceder à destruição de todas as cópias da mesma.
This message contains information that may be privileged or confidential. If
you receive this message in error please notify the sender immediately and
delete all copies of this message.