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

String in XSLT

117 100+
i ma usin gthe extension object in XSLT and then passing a string to XSLT like this
Expand|Select|Wrap|Line Numbers
  1. for(int i=0;i<xmlnode.Count;i++)
  2. {
  3.     XmlAttributeCollection xmlattrc = xmlnode[i].Attributes;
  4.  
  5.     all += "<br>";
  6.     all += xmlattrc[0].Name;
  7.     all += xmlattrc[0].Value;
  8.  
  9.     all += "<br>";
  10.     all += xmlnode[i].FirstChild.Name;
  11.     all += xmlnode[i].FirstChild.InnerText;
  12.  
  13.  
  14.     all += xmlnode[i].LastChild.Name;
  15.     all += xmlnode[i].LastChild.InnerText;
  16.  
  17. }
  18. return all;
  19.  
and then using it in XSLT like this

<xsl:value-of select="RDisc:GetAllData()" />

but is showing data in one line also included the <br> how i can solve this. I have also tried as

all +=&lt;br&gt;
Mar 6 '07 #1
14 2206
dorinbogdan
839 Expert 512MB
See this thread.
Mar 6 '07 #2
dorinbogdan
839 Expert 512MB
And see this link too.
Mar 6 '07 #3
sani723
117 100+
not working
Mar 7 '07 #4
dorinbogdan
839 Expert 512MB
Could you post the XSL and a relevant part of the XML to test?
Mar 7 '07 #5
sani723
117 100+
here is the XML file

XML
[html]
<?xml version="1.0"?>
<data>
<room type="Single">
<units>1</units>
<extrabed>0</extrabed>
</room>
<room type="Double">
<units>2</units>
<extrabed>0</extrabed>
</room>
<room type="TSU">
<units>3</units>
<extrabed>0</extrabed>
</room>
<room type="Triple">
<units>4</units>
<extrabed>0</extrabed>
</room>
<room type="Quad">
<units>5</units>
<extrabed>0</extrabed>
</room>
</data>
[/html]

and here is the CSharp Class


Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Xml;
  3. using System.IO;
  4.  
  5. namespace creport.component
  6. {
  7.     /// <summary>
  8.     /// Summary description for discount.
  9.     /// </summary>
  10.     public class discount
  11.     {
  12.         public discount()
  13.         {
  14.             //
  15.             // TODO: Add constructor logic here
  16.             //
  17.         }
  18.  
  19.         public string ReturnTotalAmount(int a)
  20.         {
  21.             XmlDocument xmldoc;
  22.             string path = System.Web.HttpContext.Current.Server.MapPath("stu2.xml");
  23.             FileStream fs = new FileStream(path,FileMode.Open,FileAccess.Read,FileShare.ReadWrite);
  24.             xmldoc = new XmlDocument();
  25.             xmldoc.Load(fs);
  26.  
  27.  
  28.             XmlNodeList xmlnode = xmldoc.GetElementsByTagName("room");
  29.  
  30.             string u="",e="";
  31.  
  32.             for(int i=0;i<xmlnode.Count;i++)
  33.             {
  34.                 XmlAttributeCollection xmlattrc = xmlnode[i].Attributes;
  35.  
  36.                 if (xmlattrc[0].Value == "Single" && a == 1)
  37.                 {
  38.                     u = xmlnode[i].FirstChild.InnerText;
  39.                     e = xmlnode[i].LastChild.InnerText;
  40.  
  41.                 }
  42.                 if (xmlattrc[0].Value == "Double" && a == 2)
  43.                 {
  44.                     u = xmlnode[i].FirstChild.InnerText;
  45.                     e = xmlnode[i].LastChild.InnerText;
  46.  
  47.                 }
  48.                 if (xmlattrc[0].Value == "TSU" && a == 3)
  49.                 {
  50.                     u = xmlnode[i].FirstChild.InnerText;
  51.                     e = xmlnode[i].LastChild.InnerText;
  52.  
  53.                 }
  54.                 if (xmlattrc[0].Value == "Triple" && a == 4)
  55.                 {
  56.                     u = xmlnode[i].FirstChild.InnerText;
  57.                     e = xmlnode[i].LastChild.InnerText;
  58.  
  59.                 }
  60.                 if (xmlattrc[0].Value == "Quad" && a == 5)
  61.                 {
  62.                     u = xmlnode[i].FirstChild.InnerText;
  63.                     e = xmlnode[i].LastChild.InnerText;
  64.  
  65.                 }
  66.  
  67.             }
  68.  
  69.             string str = u + "," + e; 
  70.             return str;
  71.             fs.Close(); 
  72.             fs = null;
  73.             xmldoc = null;
  74.         }
  75.  
  76.  
  77.         public string GetAllData()
  78.         {
  79.             XmlDocument xmldoc;
  80.             string path = System.Web.HttpContext.Current.Server.MapPath("stu2.xml");
  81.  
  82.             FileStream fs = new FileStream(path,FileMode.Open,FileAccess.Read,FileShare.ReadWrite);
  83.             xmldoc = new XmlDocument();
  84.             xmldoc.Load(fs);
  85.  
  86.             XmlNodeList xmlnode = xmldoc.GetElementsByTagName("room");
  87.  
  88.             string all="";
  89.  
  90.             for(int i=0;i<xmlnode.Count;i++)
  91.             {
  92.                 XmlAttributeCollection xmlattrc = xmlnode[i].Attributes;
  93.  
  94.                 all += "&lt;br /&gt;"; // and i also tried this "<br />"
  95.                 all += xmlattrc[0].Name;
  96.                 all += xmlattrc[0].Value;
  97.  
  98.                 all += "&lt;br /&gt;";
  99.                 all += xmlnode[i].FirstChild.Name;
  100.                 all += xmlnode[i].FirstChild.InnerText;
  101.  
  102.  
  103.                 all += xmlnode[i].LastChild.Name;
  104.                 all += xmlnode[i].LastChild.InnerText;
  105.  
  106.             }
  107.             return all;
  108.             fs.Close(); 
  109.             fs = null;
  110.             xmldoc = null;
  111.         }
  112.  
  113.  
  114.     }
  115. }
  116.  
  117.  
XSLT Code
Expand|Select|Wrap|Line Numbers
  1. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:myDiscount="urn:myDiscount" version="1.0">
  2.  <tr>
  3.     <td  class="gridHeader">Your Requirement</td>
  4.   </tr>
  5.   <tr>
  6.     <td class="SearchResultItem">
  7.     <xsl:value-of select="myDiscount:GetAllData()" />
  8.     </td>
  9.   </tr>
  10.  
Extension Object:
Expand|Select|Wrap|Line Numbers
  1. discount obj = new discount(); 
  2. args.AddExtensionObject("urn:myDiscount",obj);
Mar 7 '07 #6
sani723
117 100+
Output

if i use &lt;br /&gt; the
Expand|Select|Wrap|Line Numbers
  1. &lt;br /&gt;typeSingle&lt;br /&gt;units1extrabed0&lt;br /&gt;typeDouble&lt;br /&gt;units2extrabed0&lt;br /&gt;typeTSU&lt;br /&gt;units3extrabed0&lt;br /&gt;typeTriple&lt;br /&gt;units4extrabed0&lt;br /&gt;typeQuad&lt;br /&gt;units5extrabed0
  2.  
else
Expand|Select|Wrap|Line Numbers
  1. <br />typeSingle<br />units1extrabed0<br />typeDouble<br />units2extrabed0<br />typeTSU<br />units3extrabed0<br />typeTriple<br />units4extrabed0<br />typeQuad<br />units5extrabed0
Mar 7 '07 #7
sani723
117 100+
waiting for reply
Mar 8 '07 #8
sani723
117 100+
come on i am still waiting fro reply, is there anyone
Mar 8 '07 #9
dorinbogdan
839 Expert 512MB
Use the case that generates the second output (with <br />) , but add the
[html]xsl:output method="html"[/html] to the XSL as the second line.

If still not working , use:
Expand|Select|Wrap|Line Numbers
  1. //in code you must remove the spaces from "& # 1 0 ;" 
  2. //I added spaces just to stop browser from interpreting it
  3. all += "& # 1 0 ;" 
  4. //instead of 
  5. all += "&lt;br /&gt;"
Also, add <pre> or <div> tags in XSL:
[html]<pre>
<xsl:value-of select="myDiscount:GetAllData()" />
</pre>
[/html]

Please let me know the result.
Mar 8 '07 #10
sani723
117 100+
not working, still same result
Mar 8 '07 #11
dorinbogdan
839 Expert 512MB
Let me know to see how you could send me all required files with source code and resources in order to test your project locally.
Are you agree with this?
At this point I have no other idea.
Mar 8 '07 #12
dorinbogdan
839 Expert 512MB
1. This is the method to attach files:

"Posters can attach files zip files up to 39kb to a post. This is done by posting a dummy post with at least 10 characters (minimum requirement) then edit the post straight away (there is a 5 min limit) and the option to attach a file is available."

So you need to add a short message reply, then Submit it, and then reopen it for Edit (not later than 5 min), and Manage Attachments button appears.

Just attach the source code, without XML, XSL...that already was included before.

2. If it seems too complicate, then help me to create a similar project, and give some details.
Mar 8 '07 #13
dorinbogdan
839 Expert 512MB
Hi,
Did you succeed to solve the problem ?
If yes, please let me know, in order to close the thread.
Thanks,
Dorin.
Mar 21 '07 #14
sani723
117 100+
no, not yet
Mar 21 '07 #15

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

Similar topics

3
by: Austin | last post by:
Hello I am wondering if anyone knows if there is a way to store string literals within an XML tag. For instance I would like to store HTML formatting data for an attribute but it keeps...
3
by: J Trost | last post by:
I was wondering if anyone knows if it is possible to do basic string replacement using XSLT even though the strings being replaced may contain "<" and ">". Here is my problem: I need to be able...
2
by: zbiszko | last post by:
Is possiple to apply xsl style on string? I have for example string (i get it from some function).: "bla bla bla <gd> bla2 bla2</gd> <br/> dsdsd<aa>dsds sd</aa> sds " i would add header and main...
3
by: Christopher Ambler | last post by:
This has to be a FAQ, but I can't seem to find the answer anywhere! I have an application that consumes a web service that returns me a string full of XML. I also have an XSLT for outputting the...
0
by: Christopher M. Lauer | last post by:
I have done my best to answer this question but can not find the proper set of commands. I would like to transform an xml file (in code behind) and display its output in a specific html tag,...
1
by: Owen | last post by:
Hello: I have some xml and xsl in string, "not in file". I want to transform the xml with xsl and the result I want in string (but in xml format). I read this sample : public class Sample {...
1
by: Yuriy | last post by:
Hi, Can anybody explain the following? Say I have the following source XML and XSLT (see below). No matter what this XSLT does. It is just a sample to show a problem. the idea is that XSLT...
2
by: Benzari.Alex | last post by:
Hello, the majority of my sites use PHP MYSQL and XSLT for dynamic pages and all of it works ok for English characters. The problem begins when I try to use Romanian or Russian characters while...
2
by: darrel | last post by:
I don't do a lot with XML, so I always get a bit lost navigating the XML classes. In the past, I've used this: xslt.Transform(doc, xslArg, Response.Output, Nothing) Which takes my xml file...
7
by: Dag Sunde | last post by:
I want to use the format-number function to output a number with a specific number of decimals, based on the content of a node... Is there any smart way to generate differnet strings based on a...
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
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
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
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
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.