xsl:variable increment

G

G.

How to increment global xsl:variable?

I've daclared variable:

<xsl:variable name="my-var" select="0" />

Somewhere else I do something like this:

<xsl:variable name="my-var" select="$my-var +1" />

but this creates new local variable and initialize it with value of global
variable.

How to increment xsl:variables? Is it even possible?

G.
 
D

DFN-CIS NetNews Service

On 09/02/2004, around 11:54, G. wrote:
G> How to increment global xsl:variable?
Basically, you don't.

G> Is it even possible?
Nope.

You might want to look at (a) rewriting you transform without the
variable or (b) look at writing a recursive transformation.
 
G

G.

So, how would you solve problem like that.

I've got XML file with presons data (names and addresses). For example:

<users>
<user>
<fname>Name 1</fname>
<lname>Surname 1</lname>
<street>street 1</street>
</user>
<user>
<fname>Name 2</fname>
<lname>Surname 2</lname>
<street>street 2</street>
</user>
<user>
<fname>Name 3</fname>
<lname>Surname 3</lname>
<street>street 3</street>
</user>
</users>

Using this file, I have to generate PDF with envelope labels. Label sheet
have two columns. If users count will be an even number, there will be no
problem. If the users number will be odd number there will be a problem. How
to slove it?

Regards,
G.
 
D

DFN-CIS NetNews Service

On 09/02/2004, around 14:33, G. wrote:

If users count will be an even number, there will be no
G> problem. If the users number will be odd number there will be a problem.How
G> to slove it?

<xsl:choose>
<xsl:when test="count(//user) mod 2 = 0">
<xsl:apply-templates mode='even'/>
</xsl:when>
<xsl:eek:therwise>
<xsl:apply-templates mode='odd'/>
</xsl:eek:therwise>
</xsl:choose>
 
G

G.

<xsl:choose>
<xsl:when test="count(//user) mod 2 = 0">
<xsl:apply-templates mode='even'/>
</xsl:when>
<xsl:eek:therwise>
<xsl:apply-templates mode='odd'/>
</xsl:eek:therwise>
</xsl:choose>

I have used

<xsl:when test="(position() mod 2)= 0">

Your solution did't work at my computer. Why? I don't know.

Now I wonder how to start write templates:

I've got

<xsl:template match="user" mode="even">
<fo:table-row>
<fo:table-cell background-color="green">
<fo:block text-align="left" text-indent="2pt"><xsl:value-of
select="fname"/> </fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:template>

<xsl:template match="user" mode="odd">
<fo:table-row>
<fo:table-cell background-color="orange">
<fo:block text-align="left" text-indent="2pt"><xsl:value-of
select="fname"/></fo:block>
</fo:table-cell>
</fo:table-row>

In 'odd mode' I shall start new table row. In 'even mode' I should end the
row. But the XML document won't be valid. How to rewrite the code to display
user envelope labels in two columns.

G.
 
D

DFN-CIS NetNews Service

On 10/02/2004, around 14:51, G. wrote:

G> Your solution did't work at my computer. Why? I don't know.
It works here although that's using my count() version rather than
position().

G> In 'odd mode' I shall start new table row. In 'even mode' I should end the
G> row. But the XML document won't be valid. How to rewrite the code to display
G> user envelope labels in two columns.
Can't you write a 'dummy' entry for the odd one?
 
G

G.

Sample input XML file:

<?xml version="1.0" encoding="windows-1250"?>
<users>
<user>
<fname>Albert</fname>
<lname>Einstein</lname>
<street>street 1</street>
</user>
<user>
<fname>Paul</fname>
<lname>Dirac</lname>
<street>street 2</street>
</user>
<user>
<fname>Issack</fname>
<lname>Newton</lname>
<street>street 3</street>
</user>
</users>


Using FOP and XSLT I would like to have PDF (!), that contains envelope
labels. There will be ten envelopes on each page. I think it will be the
best to put it in table - 2 colums and 5 rows. 1st row, 1st colum will
contain Albert Einstein name adn adres; 1st, 2nd column will contain Paul
Dirac; 2nd row 1st column will contain Newtons' data.

G.
P.S. XSLT is like atomic bomb. I fell it is powerful, but I can't have a
full contron on it (yet ;-)).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,233
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top