469,343 Members | 5,380 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,343 developers. It's quick & easy.

xsl:variable increment

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.

Jul 20 '05 #1
8 15327
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.

--
Stuart
I used to work in a blanket factory, but it folded.

Jul 20 '05 #2
G.
I was warried about that. I have to change my XSLT.
Thanks.

G.
Jul 20 '05 #3
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.

Jul 20 '05 #4
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:otherwise>
<xsl:apply-templates mode='odd'/>
</xsl:otherwise>
</xsl:choose>

--
Stuart
Local Area Network in Australia: the LAN down under.

Jul 20 '05 #5
G.
Great, thanks. I have to read more about XSLT.

G.
Jul 20 '05 #6
G.
<xsl:choose>
<xsl:when test="count(//user) mod 2 = 0">
<xsl:apply-templates mode='even'/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates mode='odd'/>
</xsl:otherwise>
</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.
Jul 20 '05 #7
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?
--
Stuart
Error: Bad command or file name! Go stand in the corner.

Jul 20 '05 #8
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 ;-)).
Jul 20 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Xeon | last post: by
4 posts views Thread by sylvain.loiseau | last post: by
10 posts views Thread by Tjerk Wolterink | last post: by
2 posts views Thread by sucheta.phatak | last post: by
5 posts views Thread by Afshar Mohebbi | last post: by
reply views Thread by Markchivs | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.