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...
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
|
|
March 25th, 2008 04:08 PM
# 2
|
Re: Displaying text from XSL variable
Do you want a seperate row <tr> for each, or just have <br/> tags after each one?
You could call a parsing template:
Code: ( text )
<xsl:call-template name="break"> <xsl:with-param name="str" select="$p"/> <xsl:with-param name="breaker" select="'('"/> </xsl:call-template> ... <xsl:template name="break"> <xsl:param name="str"/> <xsl:param name="breaker"/> <xsl:choose> <xsl:when test="substring-after($str, $breaker) = ''"/> <xsl:value-of select="$str"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="concat(substring-before($str, $breaker), $breaker)"/> <br/> <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:template>
|
|
March 26th, 2008 07:22 AM
# 3
|
Re: Displaying text from XSL variable
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....
|
|
March 26th, 2008 03:06 PM
# 4
|
Re: Displaying text from XSL variable
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
Code: ( text )
<xsl:template match="root"> ... some code .. .. some more code. <xsl:call-template .... /> .. some more code </xsl:template> .. more templates. <xsl:template name="break"/> ...
|
|
March 27th, 2008 05:02 AM
# 5
|
Re: Displaying text from XSL variable
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...
|
|
March 27th, 2008 02:26 PM
# 6
|
Re: Displaying text from XSL variable
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.
Code: ( text )
<xsl:value-of select="translate(@someAttributeName,')', ')<br />')" /> <!-- or --> <xsl:value-of select="translate(@someAttributeName,')', ')<br />')" />
Last edited by pronerd : March 27th, 2008 at 02:30 PM.
Reason: Need to correct escape characters
|
|
March 27th, 2008 03:16 PM
# 7
|
Re: Displaying text from XSL variable
I used the wrong parentheses for breaker
<xsl:with-param name="breaker" select="')'"/>
sorry for my carelessness.
|
|
March 28th, 2008 10:14 AM
# 8
|
Re: Displaying text from XSL variable
Thanks a lot.....
can u give me ur mail id....?
|
|
March 28th, 2008 11:12 AM
# 9
|
Re: Displaying text from XSL variable
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)
|
|
March 28th, 2008 02:02 PM
# 10
|
Re: Displaying text from XSL variable
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.
Code: ( text )
<xsl:template name="someTemplate"> <xsl:param name="counter" /> <!-- Increment the counter --> <xsl:variable name="newCounter"> <xsl:value-of select="$counter + 1"/> </xsl:variable> <!-- Blah Blah Blah Do some stuff here--> <xsl:call-template name="someTemplate" > <xsl:with-param name="outPutText" select="$newCounter" /> </xsl:call-template> </xsl:template>
|
|
March 28th, 2008 03:15 PM
# 11
|
Re: Displaying text from XSL variable
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"/>
|
|
April 1st, 2008 05:48 AM
# 12
|
Re: Displaying text from XSL variable
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....
|
|
April 1st, 2008 04:05 PM
# 13
|
Re: Displaying text from XSL variable
Quote:
Originally Posted by jkmyoung
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?
|
|
April 1st, 2008 05:52 PM
# 14
|
Re: Displaying text from XSL variable
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
Code: ( text )
<xsl:value-of select="$str"/> and <xsl:value-of select="concat(substring-before($str, $breaker), $breaker)"/>
You'd have
Code: ( text )
<xsl:call-template name="formatTriplet"> <xsl:with-param name="str" select="$str"/> </xsl:call-template> and <xsl:call-template name="formatTriplet"> <xsl:with-param name="str" select="concat(substring-before($str, $breaker), $breaker)"/> </xsl:call-template>
Inside the formatTriplet function, get each of the numbers and format it like so:
Code: ( text )
<xsl:value-of select="format-number($number, '0.0')"/>
|
|
April 4th, 2008 10:06 AM
# 15
|
Re: Displaying text from XSL variable
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....
|
|
April 7th, 2008 04:25 AM
# 16
|
Re: Displaying text from XSL variable
I have one more problem in displaying....
i want to insert space in between points...or we can say here < > does not work, so can u tell me how can we insert space?
|
|
May 21st, 2008 05:21 AM
# 17
|
Re: Displaying text from XSL variable
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?
|
|
June 2nd, 2008 09:48 AM
# 18
|
Re: Displaying text from XSL variable
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>
 |
Not the answer you were looking for? Post your question . . .
173,562 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).
|
|
|
Top XML Forum Contributors
|