Hi Andreas,
The easiest way to deal with this is with recursion:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="logging">
<xsl:if test="child::target[1]">
<xsl:call-template name="output-targets">
<xsl:with-param name="nodes" select="child::target"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template name="output-targets">
<xsl:param name="nodes"/>
<xsl:param name="pos" select="1"/>
<xsl:param name="value" select="1"/>
<xsl:choose>
<xsl:when test="$nodes[$pos]">
<xsl:text>public static final int </xsl:text>
<xsl:value-of select="translate($nodes[$pos]/@name,
'abcdefghijklmnopqrstuvwxyz',
'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
<xsl:text> = </xsl:text>
<xsl:value-of select="$value"/>
<xsl:text>;
</xsl:text>
<xsl:call-template name="output-targets">
<xsl:with-param name="nodes" select="$nodes"/>
<xsl:with-param name="pos" select="$pos + 1"/>
<xsl:with-param name="value" select="$value * 2"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:text>public static final int ALL = </xsl:text>
<xsl:value-of select="$value"/>
<xsl:text>;
</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
-----Original Message-----
From: Andreas Mecky [mailto:andreasmecky(_at_)yahoo(_dot_)de]
Sent: 22 January 2003 09:06
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] calculating pow of numbers and a final sum
Hello everybody,
I am kind of a newbie to this mailing list and I have a problem that keeps
me busy for some time now.
I am working on a code generator for some java classes.
This is my XML:
<?xml version="1.0" ?>
<logging>
<target name="init"/>
<target name="debug"/>
<target name="fatal"/>
</logging>
this should result in:
public static final int INIT = 1;
public static final int DEBUG = 2;
public static final int FATAL = 4;
public static final int ALL = 8;
I can get everything working except the numbers. How can I calculate the
numbers which
are something like counter=2^(pos-1)?
This all entry is generated automatically. At this point I need either to
sum all former values
or do the same calculation as mentioned above.
Some research on google did not helped me out.
Any suggestions?
Thanx in advance
Andreas
__________________________________________________________________
Gesendet von Yahoo! Mail - http://mail.yahoo.de
Bis zu 100 MB Speicher bei http://premiummail.yahoo.de
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
***************************************************************************
This communication (including any attachments) contains confidential
information. If you are not the intended recipient and you have received this
communication in error, you should destroy it without copying, disclosing or
otherwise using its contents. Please notify the sender immediately of the
error.
Internet communications are not necessarily secure and may be intercepted or
changed after they are sent. Abbey National Treasury Services plc does not
accept liability for any loss you may suffer as a result of interception or any
liability for such changes. If you wish to confirm the origin or content of
this communication, please contact the sender by using an alternative means of
communication.
This communication does not create or modify any contract and, unless otherwise
stated, is not intended to be contractually binding.
Abbey National Treasury Services plc. Registered Office: Abbey National House,
2 Triton Square, Regents Place, London NW1 3AN. Registered in England under
Company Registration Number: 2338548. Regulated by the Financial Services
Authority (FSA).
***************************************************************************
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list