472,333 Members | 1,107 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,333 software developers and data experts.

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 15432
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Xeon | last post by:
Hi, I'm trying this code snippet below but the parser (sablotron) returns error : <xsl:choose> <xsl:when test="some test case">...
4
by: sylvain.loiseau | last post by:
Hello Given a node set, I try to compute the total of the string-length value of each node. For instance, with : <xsl:for-each...
2
by: Richard | last post by:
Suppose I create a variable named "var" such as: <xsl:variable name="var">VarValue</xsl:variable> and then I want to insert its value into an...
10
by: Tjerk Wolterink | last post by:
The following code does not work: <xsl:variable name="width" select="form:image-width"/> <xsl:if test="$width>$max_image_width"> <xsl:variable...
1
by: schaf | last post by:
Hello NG ! I have a big problem. I would like to go through a xml file in a xsl:for-each statement. for-each entry (ID) in the XML file i would...
2
by: sucheta.phatak | last post by:
Hello, I am trying to use XSLT. Here is the problem that I am facing. My XML file: <Book level="1" name="Mapplicationtoc1"> ....... Some...
5
by: Afshar Mohebbi | last post by:
Hi everybody there, I've declared a <xsl:variable name="something" select="999"/> in my xslt and when I want to set another value in it (with same...
2
by: jobooker | last post by:
I'm having issues sorting. The short description is, how do I set the select attribute of xsl:sort to be the value of an xsl:variable? The longer...
0
by: Markchivs | last post by:
Hi all, I wonder if anyone can shed any light on this problem for me? In the following code I'm trying to set a variable called 'atts' with a...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.