473,387 Members | 1,903 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,387 software developers and data experts.

Display values

My xml looks like

<abc>
23 45 67 2 123
</abc>

I wish to display these values comma separated

23; 45; 67; 2; 123

However if I use <xsl:value-of select="abc"> I get the entire list of
values i.e. all 5 values. How can I obtain each component of the value?
I cannot use for-each to select the value of each child as abc has no
children in this case. Or should I modify the xml itself to include the
comma?

TIA.

Jul 20 '05 #1
3 2432
"Ravi" <rg**@cse.buffalo.edu> wrote in message
news:bo**********@prometheus.acsu.buffalo.edu...
My xml looks like

<abc>
23 45 67 2 123
</abc>

I wish to display these values comma separated

23; 45; 67; 2; 123

However if I use <xsl:value-of select="abc"> I get the entire list of
values i.e. all 5 values. How can I obtain each component of the value?
I cannot use for-each to select the value of each child as abc has no
children in this case. Or should I modify the xml itself to include the
comma?


If you can modify the XML, you might start generating it as
<abc>
<nr>23</nr>
<nr>56</nr>
<nr>67</nr>
<nr>2</nr>
<nr>123</nr>
</abc>
which would make transforming it into a separated list a lot easier.

With your current XML, it would be possible using a recursive template
and the substring-before function.

The root of the problem is that five distinct entities have been rolled
into a single text node.

Groetjes,
Maarten Wiltink
Jul 20 '05 #2
Ravi wrote:
My xml looks like

<abc>
23 45 67 2 123
</abc>

I wish to display these values comma separated

23; 45; 67; 2; 123


<xsl:value-of select="translate(abc,' ',';')"/>

will result in

23;45;67;2;123
--
Johannes Koch
In te domine speravi; non confundar in aeternum.
(Te Deum, 4th cent.)

Jul 20 '05 #3
In article <bo**********@prometheus.acsu.buffalo.edu>,
Ravi <rg**@cse.buffalo.edu> wrote:

% <abc>
% 23 45 67 2 123
% </abc>
%
% I wish to display these values comma separated
%
% 23; 45; 67; 2; 123

Those are semi-colons, not commas. To do this in XSLT, you need to
create a recursive template. The approach is to create a template which
takes two arguments, s and t. If the s is zero-length, the template
emits t. Otherwise, it builds new arguments, moving the first word of s
to the end of t, and calls itself.

<xsl:template match="abc">
<xsl:call-template name="semi-colonify">
<xsl:with-param name="s" select="string(.)"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="semi-colonify">
<xsl:param name="s"/>
<xsl:param name="t"/>

<xsl:choose>
<!-- s is not zero-length, so split it -->
<xsl:when test="$s">
<xsl:call-template name="semi-colonify">
<xsl:with-param name="t">
<!-- need to fiddle if there's already a t -->
<xsl:if test="$t">
<xsl:value-of select="$t"/>
<xsl:text>; </xsl:text>
</xsl:if>
<xsl:variable name="sbs" select="substring-before($s, ' ')"/>
<xsl:choose>
<xsl:when test="$sbs">
<xsl:value-of select="$sbs"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$s"/>
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>

<xsl:with-param name="s" select="substring-after($s, ' ')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$t"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

XSLT can handle most string processing problems, but you may find
it's easier to use another language. You have to balance portability
requirements against your ability to be productive. For instance,
this could be done with Rexx:

<rexx:function name='my:semi-colonify' all-strings='yes'>
return changestr(' ', arg(1), '; ')
</rexx:function>

<xsl:template match="abc">
<xsl:value-of select='my:semi-colonify(.)'/>
</xsl:template>

Something similar can likely be done equally portably using python or
a bit more portably using ecma script.
--

Patrick TJ McPhee
East York Canada
pt**@interlog.com
Jul 20 '05 #4

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

Similar topics

13
by: Dan R Brown | last post by:
I have a large form that is generated dynamically in a jsp using xml / xslt. So, to break up this form into several "tabbed" sections, I break up the form using <div> tags. Each <div...
4
by: Lachlan Hunt | last post by:
Hi, I was wondering if ::before and ::after pseudo-elements can apply to elements styled with the display: table-* properties. None of my tests worked in either Firefox or Opera, yet I could not...
19
by: dmiller23462 | last post by:
Hi guys....I have absolutely NO IDEA what I'm doing with Javascript but my end result is I need two text boxes to stay hidden until a particular option is selected....I've cobbled together the...
6
by: Sandman | last post by:
I'm having some problem here... I have a javascript I've downloaded that goes through all PNG files and enables the transparency channel in them for IE5.5+ by converting them to SPAN layers with...
0
by: Elvis V. | last post by:
Good morning, I have a table that contains three fields that I would like to relate one to another, in other words, for example, when I go to the form and I click on the drop down box for...
3
by: Gopal Krish | last post by:
I need to display uniqueidentifier (GUID) from a table in SQL Server into a ASP.NET Web Page (Combo box). I'm using C#. When I tried to display GUIDs in a combo box I get "System.Byte" for all...
3
by: Miguel Dias Moura | last post by:
Hello, I am working in ASP.NET/VB and I need to see a string value. Howe can I display the string values and also only one of the values? Thanks, Miguel
2
by: assgar | last post by:
Hi Developemnt on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. I use 2 scripts(form and process). The form displays multiple dynamic rows with chechboxs,...
1
by: Regnab | last post by:
I've got a form where the user can edit the lookups available in the database. It consists of a list box of the various categories on the main form, a checkbox on the main form and a sub form which...
2
ak1dnar
by: ak1dnar | last post by:
CREATE TABLE `products` ( `p_id` int(11) NOT NULL, `p_name` varchar(15) default NULL, `p_features` varchar(100) default NULL ) from this table I am going to fetch the records and display...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.