473,395 Members | 2,446 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,395 software developers and data experts.

Displaying text from XSL variable

I have a XSL variable named $p = (0 0 0) (0.82 0 0) (1.63 -0.01 0) (2.63 -0.01 0) (3.63 -0.01 0) (4.63 -0.01 0) (5.63 -0.02 0) (6.63 -0.02 0) (7.63 -0.02 0) (8.6 -0.02 0)
This line contains X,Y,Z coordinates of 10 points.
I am using this code for displaying
<td><font size="-2"><xsl:value-of select="$p"/></font></td>
but i want to display each coordinate in a separate line.Like this....
(0 0 0)
(0.82 0 0)
(1.63 -0.01 0)
(2.63 -0.01 0)
(3.63 -0.01 0)
(4.63 -0.01 0)
(5.63 -0.02 0)
(6.63 -0.02 0)
(7.63 -0.02 0)
(8.6 -0.02 0)

So plz help...
Mar 25 '08 #1
17 3087
jkmyoung
2,057 Expert 2GB
Do you want a seperate row <tr> for each, or just have <br/> tags after each one?

You could call a parsing template:
Expand|Select|Wrap|Line Numbers
  1. <xsl:call-template name="break">
  2.   <xsl:with-param name="str" select="$p"/>
  3.   <xsl:with-param name="breaker" select="'('"/>
  4. </xsl:call-template>
  5. ...
  6. <xsl:template name="break">
  7.   <xsl:param name="str"/>
  8.   <xsl:param name="breaker"/>
  9.   <xsl:choose>
  10.     <xsl:when test="substring-after($str, $breaker) = ''"/>
  11.       <xsl:value-of select="$str"/>
  12.     </xsl:when>
  13.     <xsl:otherwise>
  14.       <xsl:value-of select="concat(substring-before($str, $breaker), $breaker)"/>
  15.       <br/>
  16.        <xsl:call-template name="break">
  17.           <xsl:with-param name="str" select="substring-after($str, $breaker)"/>
  18.           <xsl:with-param name="breaker" select="$breaker"/>
  19.        </xsl:call-template>
  20.     </xsl:otherwise>
  21. </xsl:template>
  22.  
  23.  
Mar 25 '08 #2
Hi jkmyoung,
thanks for help, i want to use <br> tag, but the code given by you have some minor error (related to tagging), i corrected that as

in line 8 <xsl:param name="breaker"\>
in line 18 <xsl:with-param name="breaker" select="$breaker)"/>
after line 20 insert one more line </xsl:choose>
in line 10 <xsl:when test="substring-after($str, $breaker) = ''"/>

after these changes the error comes like this
Keyword xsl:template may not be used here
can you give me your mail id so that i can send you my XML and XSL file?
plz help....
Mar 26 '08 #3
jkmyoung
2,057 Expert 2GB
Sorry, the line should be: (without parentheses at the end)
<xsl:with-param name="breaker" select="$breaker"/>

The call-template should be inside some template, the other template has to be just under the root level

Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="root">
  2.   ... some code ..
  3.   .. some more code.
  4.   <xsl:call-template .... />
  5.   .. some more code
  6.   </xsl:template>
  7.   .. more templates.
  8. <xsl:template name="break"/>
  9. ...
  10.  
  11.  
Mar 26 '08 #4
Thanks jkmyoung
it is working now....but having a minor problem
in output it is displaying like this
(
0 0 0) (
0.82 0 0) (
1.63 -0.01 0) (
2.63 -0.01 0) (
3.63 -0.01 0) (
4.63 -0.01 0) (
5.63 -0.02 0) (
6.63 -0.02 0) (
7.63 -0.02 0) (
8.6 -0.02 0) (

i changed one line as
<xsl:value-of select="concat($breaker,substring-before($str, $breaker))"/>
and now it is displaying like this
(
(0 0 0)
(0.82 0 0)
(1.63 -0.01 0)
(2.63 -0.01 0)
(3.63 -0.01 0)
(4.63 -0.01 0)
(5.63 -0.02 0)
(6.63 -0.02 0)
(7.63 -0.02 0)
8.6 -0.02 0)

in 1st line we are getting 1 extra small braces and in last line one braces is off.
so plz help...
Mar 27 '08 #5
pronerd
392 Expert 256MB
There is a potentially simpler option. Since what you are really wanting to do is add a br element after each closing ")". You should be able to use the translate() function to convert ")" to ")<br />". There is some trick to escaping element tags in the function strings that I do not re-call off hand.


Expand|Select|Wrap|Line Numbers
  1.  
  2.     <xsl:value-of select="translate(@someAttributeName,')', ')<br />')" />   
  3.  
  4.     <!--  or -->
  5.  
  6.     <xsl:value-of select="translate(@someAttributeName,')', ')&amp;lt;br /&amp;gt;')" />
  7.  
  8.  
Mar 27 '08 #6
jkmyoung
2,057 Expert 2GB
I used the wrong parentheses for breaker
<xsl:with-param name="breaker" select="')'"/>

sorry for my carelessness.
Mar 27 '08 #7
Thanks a lot.....
can u give me ur mail id....?
Mar 28 '08 #8
how can we insert the serial number in the beginning for displaying like this....
1. (0 0 0)
2. (0.82 0 0)
3. (1.63 -0.01 0)
4. (2.63 -0.01 0)
5. (3.63 -0.01 0)
6. (4.63 -0.01 0)
7. (5.63 -0.02 0)
8. (6.63 -0.02 0)
9. (7.63 -0.02 0)
10. (8.6 -0.02 0)

I tried this by declaring two XSL variables before template definition

<xsl:variable name="temp" select="1"/>
<xsl:variable name="one" select="1"/>

and then after these statements
</xsl:when>
<xsl:otherwise>

I inserted these lines of code

<xsl:variable name="temp" select=" $temp + $one "/>
<xsl:value-of select="$temp"/>

but it didn't work, it comes like this

2 (0 0 0)
2 (0.82 0 0)
2 (1.63 -0.01 0)
2 (2.63 -0.01 0)
2 (3.63 -0.01 0)
2 (4.63 -0.01 0)
2 (5.63 -0.02 0)
2 (6.63 -0.02 0)
2 (7.63 -0.02 0)
2 (8.6 -0.02 0)
Mar 28 '08 #9
pronerd
392 Expert 256MB
Since 1 + 1 always equals 2 that is all that will ever return. Incrementing counters are difficult to do in XSL since it does not use variables in the normal way we think of them.

The only way I have ever been able to do an incrementing counter in XSL is to use it in a recursive template call which I do not think will work for you.


Expand|Select|Wrap|Line Numbers
  1.  
  2.     <xsl:template name="someTemplate">
  3.         <xsl:param name="counter" />
  4.  
  5.         <!--  Increment the counter -->
  6.         <xsl:variable name="newCounter">
  7.             <xsl:value-of select="$counter + 1"/>
  8.         </xsl:variable>
  9.  
  10.         <!--   Blah Blah Blah Do some stuff here-->
  11.  
  12.         <xsl:call-template name="someTemplate" >
  13.             <xsl:with-param name="outPutText" select="$newCounter" />
  14.         </xsl:call-template>
  15.  
  16.     </xsl:template>
  17.  
  18.  
Mar 28 '08 #10
jkmyoung
2,057 Expert 2GB
With respect to above post, you are using a recursive template.
Add the param to the initial call:
<xsl:with-param name="counter" select="1"/>

Delcare it in the template:
<xsl:param name="counter"/>

Output it when needed:
<xsl:value-of select="$counter"/>

And when doing the recursive call, add 1 to it.
<xsl:with-param name="counter" select="$counter +1"/>
Mar 28 '08 #11
Thanx a lot...its working...
now if i want round off the value upto 1 decimal place, then how can we do it.
i m using this line of code
<xsl:value-of select="concat ( substring-before( $x, '.' ) , '.' , substring ( substring-after ( $x, '.' ) , 1 ,2) )" />

but for point like (0 0 0),it is displaying ( .. ). It will not display 0 (zero) value.
so plz help....
Apr 1 '08 #12
pronerd
392 Expert 256MB
With respect to above post, you are using a recursive template.
Add the param to the initial call:
<xsl:with-param name="counter" select="1"/>

Delcare it in the template:
<xsl:param name="counter"/>

Output it when needed:
<xsl:value-of select="$counter"/>

And when doing the recursive call, add 1 to it.
<xsl:with-param name="counter" select="$counter +1"/>
Isn't that exactly what I posted?
Apr 1 '08 #13
jkmyoung
2,057 Expert 2GB
Your problem there is that it assumes that there is a decimal place. I suggest format-number() for this type of formatting:
http://www.w3schools.com/xsl/func_formatnumber.asp

Unfortunately, this also means parsing each of the insides of the brackets. I would suggest another template to parse the inside
So instead of
Expand|Select|Wrap|Line Numbers
  1. <xsl:value-of select="$str"/>
  2. and
  3. <xsl:value-of select="concat(substring-before($str, $breaker), $breaker)"/>
  4.  
You'd have
Expand|Select|Wrap|Line Numbers
  1. <xsl:call-template name="formatTriplet">
  2.   <xsl:with-param name="str" select="$str"/>
  3. </xsl:call-template>
  4. and
  5. <xsl:call-template name="formatTriplet">
  6.   <xsl:with-param name="str" select="concat(substring-before($str, $breaker), $breaker)"/>
  7. </xsl:call-template>
  8.  
Inside the formatTriplet function, get each of the numbers and format it like so:
Expand|Select|Wrap|Line Numbers
  1. <xsl:value-of select="format-number($number, '0.0')"/>
Apr 1 '08 #14
Thanx.....Now i want to update the XML file....
i have a XML file, for that XML file i made a XSL file,this XSL file showing the data of XML file in a HTML form, data shown in text boxes, so that we can edit the data and a submit button is also present. Now when we click submit button,there is an action field that points to the ASP file,now i want to update the data of XML file.

http://www.asp101.com/articles/michael/editingxml/

I am using ASP till now, but the problem is if the value of the 'id' attribute is same for all field than problem comes. and other problem is-lets assume value of 'id' attribute is unique then if we want to update the value of both field_value as well as taborder, then how can we do this....
Apr 4 '08 #15
I have one more problem in displaying....
i want to insert space in between points...or we can say here <&nbsp> does not work, so can u tell me how can we insert space?
Apr 7 '08 #16
Now i have one more problem.
NOW THE PROBLEM is this, that in IE 6.0 its displaying all the points in different row, but when i open that file in mozilla,it displays all the points in a single row. can any one help me that how can it display each point in different row in mozilla?
May 21 '08 #17
My template is this

<xsl:template name="break">
<xsl:param name="str"/>
<xsl:param name="breaker"/>
<xsl:choose>
<xsl:when test="substring-after($str, $breaker) = ''">
<xsl:variable name="last"><xsl:value-of select="$str"/></xsl:variable>
</xsl:when>

<xsl:otherwise>
<xsl:variable name="s"><xsl:value-of select="concat(substring-before($str, $breaker),$breaker)"/></xsl:variable>

<table border="0" cellspacing="0" cellpadding="0" width="300">
<tr>
<td align="left" width="100">
<xsl:variable name="tmpStr_01" select="(substring-after($s,'('))"/>
<xsl:variable name="x" select="number(substring-before($tmpStr_01,' '))"/>
<font color="black" face="Verdana, Arial, Helvetica, sans-serif" size="2">
<xsl:value-of select="format-number($x, '0.00')"/>
</font>
</td>
<td align="left" width="100">
<xsl:variable name="tmpStr_02" select="(substring-after($tmpStr_01,' '))"/>
<xsl:variable name="y" select="number(substring-before($tmpStr_02,' '))"/>
<font color="black" face="Verdana, Arial, Helvetica, sans-serif" size="2">
<xsl:value-of select="format-number($y, '0.00')"/>
</font>
</td>
<td align="left" width="100">
<xsl:variable name="tmpStr_03" select="(substring-after($tmpStr_02,' '))"/>
<xsl:variable name="z" select="number(substring-before($tmpStr_03,')'))"/>
<font color="black" face="Verdana, Arial, Helvetica, sans-serif" size="2">
<xsl:value-of select="format-number($z, '0.00')"/>
</font>
</td>
</tr>
</table>

<xsl:call-template name="break">
<xsl:with-param name="str" select="substring-after($str, $breaker)"/>
<xsl:with-param name="breaker" select="$breaker"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Jun 2 '08 #18

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: JimJones | last post by:
Hey, I don't really know much about ASP but I need some help modifying the way a field is currently displayed. Currently the ASP code inside my page is simply: <%=rs.Fields("Notes")%> ...
0
by: Wynter | last post by:
RE: from Displaying a Document using the ASPNET user account to the Client Browser discussion (3/2/2004 Buddy Thanks for helping me on getting the document to display. But now I am left with a...
5
by: nbohana | last post by:
I have a windows form with several fields. One of the fields is a date. I use DateTimePicker to enter and format the date. In my SQL table the date si stored as follows "01/10/2005" and this is...
7
by: Terry | last post by:
I have a Mainform with a Statusbar. When opening another form or doing some processing I want to display info in the Statusbar of the Mainform. I have read a lot of articles on this & have come up...
5
by: Bill | last post by:
Hello, Could anyone post some simple code or advise me on how I can display the SSN number like *****7890 in a text box, even thought the user entered 1234567890, and the value of the variable...
2
by: moumita | last post by:
I have the folowing code..the logic according to me is correct..but I dont know...the msg boxes are not displaying anything...am I supposed to change any settings ??? Public Class Form1
12
by: brwalias | last post by:
Hi, using .net 2 sql server 2005 Here is my situation: I'm passing a variable in the url from a selection on Page A and need to display the results on the Results page be based on that...
0
by: paragguptaiiita | last post by:
I have one problem regarding displaying text from XML file. I have a XSL variable named $p = (0 0 0) (0.82 0 0) (1.63 -0.01 0) (2.63 -0.01 0) (3.63 -0.01 0) (4.63 -0.01 0) (5.63 -0.02 0) (6.63 -0.02...
0
by: paragguptaiiita | last post by:
I have one problem regarding displaying text from XML file. I have a XSL variable named $p = (0 0 0) (0.82 0 0) (1.63 -0.01 0) (2.63 -0.01 0) (3.63 -0.01 0) (4.63 -0.01 0) (5.63 -0.02 0) (6.63 -0.02...
1
by: littlealex | last post by:
IE6 not displaying text correctly - IE 7 & Firefox 3 are fine! Need some help with this as fairly new to CSS! In IE6 the text for the following page doesn't display properly - rather than being...
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: 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?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.