469,279 Members | 2,200 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,279 developers. It's quick & easy.

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 1958
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

Post your reply

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

Similar topics

3 posts views Thread by Austin | last post: by
3 posts views Thread by J Trost | last post: by
2 posts views Thread by zbiszko | last post: by
reply views Thread by Christopher M. Lauer | last post: by
1 post views Thread by Owen | last post: by
2 posts views Thread by Benzari.Alex | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.