473,407 Members | 2,315 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

XSLT - extending variable

The title is quite ambiguos.
Any way let me explain.

In java, the following is possible.
----
String str = "";
for (int i=0; i < 10; i++) {
str = str + i;
}
----
the str variable becomes "0123456789".

I tried that kind thing in XSLT. but failed.
---
<xsl:variable name="str1"/>
<xsl:variable name="str2"/>

<xsl:for-each select="/ROOT/ELEMENT">
<xsl:variable name="str1">
<xsl:value-of select="$str1"/>
<xsl:value-of select="@value1"/>
</xsl:variable>
<xsl:variable name="str2">
<xsl:value-of select="$str2"/>
<xsl:value-of select="@value1"/>
</xsl:variable>
</xsl:for-each>

<tr>
<td><xsl:value-of select="$str1"/></td>
<td><xsl:value-of select="$str2"/></td>
</tr>
---
Any other way to achieve this kind operation in XSLT?

--
** Son KwonNam
http://kr.blog.yahoo.com/kwon37xi

Please DO NOT reply to this message's email address.
The address is fake.
Jul 20 '05 #1
3 7339

"Son KwonNam" <pl****@neverSendEmail.no> wrote in message
news:c8**********@news1.kornet.net...
The title is quite ambiguos.
Any way let me explain.

In java, the following is possible.
----
String str = "";
for (int i=0; i < 10; i++) {
str = str + i;
}
----

Hi,

Try this :

<xsl:template name="functionalLanguagesImplementIterationViaRecu rsiveCalls">
<xsl:param name="counter" />
<xsl:if test = "$counter &gt;= 10">
<xsl:value-of select="$counter" />
<xsl:call-template
name="functionalLanguagesImplementIterationViaRecu rsiveCalls">
<xsl:with-param name="counter" select="number($counter + 1)" />
</xsl:call-template>
</xsl:if>
</xsl:template>

.....

and call this by saying :

<xsl:variable name="str">
<xsl:call-template
name="functionalLanguagesImplementIterationViaRecu rsiveCalls">
<xsl:with-param name="counter" select="number(0)" />
</xsl:call-template>
</xsl:variable>
Regards,
Kenneth
Jul 20 '05 #2
Thanks for your quick answer.
But what I really wanted is not just add continuous numbers.
The values to be added are strings.

If there is not something like "str = str + value" in XSLT,
I should use <xsl:for-each> more than two times.
And I really did - I use <xsl:for-each> 8 times for every <td>, It gives
me horrible performance.

Kenneth Stephen ¾´ ±Û:
"Son KwonNam" <pl****@neverSendEmail.no> wrote in message
news:c8**********@news1.kornet.net...
The title is quite ambiguos.
Any way let me explain.

In java, the following is possible.
----
String str = "";
for (int i=0; i < 10; i++) {
str = str + i;
}
----


Hi,

Try this :

<xsl:template name="functionalLanguagesImplementIterationViaRecu rsiveCalls">
<xsl:param name="counter" />
<xsl:if test = "$counter &gt;= 10">
<xsl:value-of select="$counter" />
<xsl:call-template
name="functionalLanguagesImplementIterationViaRecu rsiveCalls">
<xsl:with-param name="counter" select="number($counter + 1)" />
</xsl:call-template>
</xsl:if>
</xsl:template>

....

and call this by saying :

<xsl:variable name="str">
<xsl:call-template
name="functionalLanguagesImplementIterationViaRecu rsiveCalls">
<xsl:with-param name="counter" select="number(0)" />
</xsl:call-template>
</xsl:variable>
Regards,
Kenneth

--
** Son KwonNam
http://kr.blog.yahoo.com/kwon37xi

Please DO NOT reply to this message's email address.
The address is fake.
Jul 20 '05 #3
Son KwonNam <pl****@neverSendEmail.no> writes:
But what I really wanted is not just add continuous numbers.
The values to be added are strings.

If there is not something like "str = str + value" in XSLT,
I should use <xsl:for-each> more than two times.
And I really did - I use <xsl:for-each> 8 times for every <td>, It gives
me horrible performance.


This *can* be done recursively, you just have to carry around a
few extra parameters. Here's a solution that makes a node-set
($nodes) and passes it to the recursive template along with a
pointer that keeps track of the current position. It's not
pretty, but it works OK. As for performance, I'd be interested
to know how it compares.

This XML
- - -
<foo>
<item value1="one" value2="ONE"/>
<item value1="two" value2="TWO"/>
<item value1="three" value2="THREE"/>
<item value1="four" value2="FOUR"/>
</foo>
- - -

with this transformation
- - -
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/foo">
<xsl:call-template name="concat-values">
<xsl:with-param name="num" select="1"/>
<xsl:with-param name="nodes" select="item"/>
<xsl:with-param name="string1" select="''"/>
<xsl:with-param name="string2" select="''"/>
</xsl:call-template>
</xsl:template>

<xsl:template name="concat-values">
<xsl:param name="num"/>
<xsl:param name="nodes"/>
<xsl:param name="string1"/>
<xsl:param name="string2"/>
<xsl:choose>
<xsl:when test="$nodes[$num]">
<xsl:call-template name="concat-values">
<xsl:with-param name="num" select="$num + 1"/>
<xsl:with-param name="nodes" select="$nodes"/>
<xsl:with-param name="string1"
select="concat($string1,$nodes[$num]/@value1)"/>
<xsl:with-param name="string2"
select="concat($string2,$nodes[$num]/@value2)"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:text>String1 = </xsl:text>
<xsl:value-of select="$string1"/>
<xsl:text>&#x0a;String2 = </xsl:text>
<xsl:value-of select="$string2"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

</xsl:stylesheet>
- - -

gives this output
- - -
<?xml version="1.0"?>
String1 = onetwothreefour
String2 = ONETWOTHREEFOUR
- - -

which you should be able to adapt to your situation.

Ben
--
Ben Edgington
Mail to the address above is discarded.
Mail to ben at that address might be read.
http://www.edginet.org/
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Sergio del Amo | last post by:
Hi, I use the xslt functions provided by php. I am running in my computer the package xampp(www.apachefriends.org) which includes php/apache/mysql .. In this package the php includes the sablotron...
3
by: Duane Morin | last post by:
Is this normal use of XSLT? At the top of our XSL file we have: <xsl:stylesheet ... xmlns:nl="http://www.jclark.com/xt/java/com.company.package.ProcessXML"> .... Then within the XSL itself...
1
by: Emil Karlen | last post by:
Using the import-tag, a template appearing in the imported file, can be extended in the importing file. I am extending a template this way and in the main-file, inside the template use...
5
by: inquirydog | last post by:
Hi- Does anyone know a way to compare whether two nodes contain the same information in xslt (the name, attributes, and all content recursivly should be the same. I am interested in the case...
4
by: Frederik Sørensen | last post by:
I include a xslt stylesheet with variables for all the error messages in my system. <xsl:variable name="Banner_error_1"> errormessage 1 for banner </xsl:variable> <xsl:variable...
12
by: Keith Chadwick | last post by:
I have a fairly hefty XSLT file that for the sake of debugging and clarity I wish to split into some separate sub-templates contained within the same file. The master template calls an...
2
by: Michael Hamm | last post by:
I have the following XML file (simplified from the actual): <r> <o><n>1</n><si>s</si><v1>1</v1><v2>2</v2><v3>3</v3></o> <o><n>2</n><si>i</si><v1>4</v1><v2>5</v2><v3>6</v3></o>...
2
by: 张韡武 | last post by:
We have preffered language set as variable in xslt: <xsl:variable name="preferred_language"> zh </xsl:variable> Data: <name xml:lang="de">Raw Materials (Mining incl.)</name> <name...
3
by: super.raddish | last post by:
Greetings, I am relatively new to, what I would call, advanced XSLT/XPath and I am after some advice from those in the know. I am attempting to figure out a mechanism within XSLT to compare the...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.