String in XSLT

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sani723
    New Member
    • Feb 2007
    • 117

    String in XSLT

    i ma usin gthe extension object in XSLT and then passing a string to XSLT like this
    Code:
    for(int i=0;i<xmlnode.Count;i++)
    {
    	XmlAttributeCollection xmlattrc = xmlnode[i].Attributes;
                   
    	all += "<br>";
    	all += xmlattrc[0].Name;
    	all += xmlattrc[0].Value;
    			      
    	all += "<br>";
    	all += xmlnode[i].FirstChild.Name;
    	all += xmlnode[i].FirstChild.InnerText;
    				
    				
    	all += xmlnode[i].LastChild.Name;
    	all += xmlnode[i].LastChild.InnerText;
    			
    }
    return all;
    and then using it in XSLT like this

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

    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;
    Last edited by dorinbogdan; Mar 8 '07, 11:59 AM. Reason: added code tags
  • dorinbogdan
    Recognized Expert Contributor
    • Feb 2007
    • 839

    #2
    See this thread.

    Comment

    • dorinbogdan
      Recognized Expert Contributor
      • Feb 2007
      • 839

      #3
      And see this link too.

      Comment

      • sani723
        New Member
        • Feb 2007
        • 117

        #4
        not working

        Comment

        • dorinbogdan
          Recognized Expert Contributor
          • Feb 2007
          • 839

          #5
          Could you post the XSL and a relevant part of the XML to test?

          Comment

          • sani723
            New Member
            • Feb 2007
            • 117

            #6
            code tags

            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


            Code:
            using System;
            using System.Xml;
            using System.IO;
            
            namespace creport.component
            {
            	/// <summary>
            	/// Summary description for discount.
            	/// </summary>
            	public class discount
            	{
            		public discount()
            		{
            			//
            			// TODO: Add constructor logic here
            			//
            		}
            
            		public string ReturnTotalAmount(int a)
            		{
            			XmlDocument xmldoc;
            			string path = System.Web.HttpContext.Current.Server.MapPath("stu2.xml");
            			FileStream fs = new FileStream(path,FileMode.Open,FileAccess.Read,FileShare.ReadWrite);
            			xmldoc = new XmlDocument();
            			xmldoc.Load(fs);
            
            			
            			XmlNodeList xmlnode = xmldoc.GetElementsByTagName("room");
            			
            			string u="",e="";
            
            			for(int i=0;i<xmlnode.Count;i++)
            			{
            				XmlAttributeCollection xmlattrc = xmlnode[i].Attributes;
            
            				if (xmlattrc[0].Value == "Single" && a == 1)
            				{
            					u = xmlnode[i].FirstChild.InnerText;
            					e = xmlnode[i].LastChild.InnerText;
            
            				}
            				if (xmlattrc[0].Value == "Double" && a == 2)
            				{
            					u = xmlnode[i].FirstChild.InnerText;
            					e = xmlnode[i].LastChild.InnerText;
            
            				}
            				if (xmlattrc[0].Value == "TSU" && a == 3)
            				{
            					u = xmlnode[i].FirstChild.InnerText;
            					e = xmlnode[i].LastChild.InnerText;
            
            				}
            				if (xmlattrc[0].Value == "Triple" && a == 4)
            				{
            					u = xmlnode[i].FirstChild.InnerText;
            					e = xmlnode[i].LastChild.InnerText;
            
            				}
            				if (xmlattrc[0].Value == "Quad" && a == 5)
            				{
            					u = xmlnode[i].FirstChild.InnerText;
            					e = xmlnode[i].LastChild.InnerText;
            
            				}
            
            			}
            	
            			string str = u + "," + e; 
            			return str;
            			fs.Close(); 
            			fs = null;
            			xmldoc = null;
            		}
            
            
            		public string GetAllData()
            		{
            			XmlDocument xmldoc;
            			string path = System.Web.HttpContext.Current.Server.MapPath("stu2.xml");
            
            			FileStream fs = new FileStream(path,FileMode.Open,FileAccess.Read,FileShare.ReadWrite);
            			xmldoc = new XmlDocument();
            			xmldoc.Load(fs);
            
            			XmlNodeList xmlnode = xmldoc.GetElementsByTagName("room");
            			
            			string all="";
            
            			for(int i=0;i<xmlnode.Count;i++)
            			{
            				XmlAttributeCollection xmlattrc = xmlnode[i].Attributes;
            				                
            				all += "&lt;br /&gt;"; // and i also tried this "<br />"
            				all += xmlattrc[0].Name;
            				all += xmlattrc[0].Value;
            				      
            				all += "&lt;br /&gt;";
            				all += xmlnode[i].FirstChild.Name;
            				all += xmlnode[i].FirstChild.InnerText;
            				
            				
            				all += xmlnode[i].LastChild.Name;
            				all += xmlnode[i].LastChild.InnerText;
            			
            			}
            			return all;
            			fs.Close(); 
            			fs = null;
            			xmldoc = null;
            		}
            
            		
            	}
            }
            XSLT Code
            Code:
            <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:myDiscount="urn:myDiscount" version="1.0">
             <tr>
                <td  class="gridHeader">Your Requirement</td>
              </tr>
              <tr>
                <td class="SearchResultItem">
                <xsl:value-of select="myDiscount:GetAllData()" />
                </td>
              </tr>
            Extension Object:
            Code:
            discount obj = new discount(); 
            args.AddExtensionObject("urn:myDiscount",obj);
            Last edited by dorinbogdan; Mar 8 '07, 12:02 PM. Reason: added code tags

            Comment

            • sani723
              New Member
              • Feb 2007
              • 117

              #7
              code tags

              Output

              if i use &lt;br /&gt; the
              Code:
              &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
              else
              Code:
              <br />typeSingle<br />units1extrabed0<br />typeDouble<br />units2extrabed0<br />typeTSU<br />units3extrabed0<br />typeTriple<br />units4extrabed0<br />typeQuad<br />units5extrabed0
              Last edited by dorinbogdan; Mar 8 '07, 12:04 PM. Reason: added code tags

              Comment

              • sani723
                New Member
                • Feb 2007
                • 117

                #8
                waiting for reply

                Comment

                • sani723
                  New Member
                  • Feb 2007
                  • 117

                  #9
                  come on i am still waiting fro reply, is there anyone

                  Comment

                  • dorinbogdan
                    Recognized Expert Contributor
                    • Feb 2007
                    • 839

                    #10
                    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:
                    Code:
                    //in code you must remove the spaces from "& # 1 0 ;" 
                    //I added spaces just to stop browser from interpreting it
                    all += "& # 1 0 ;" 
                    //instead of 
                    all += "&lt;br /&gt;"
                    Also, add <pre> or <div> tags in XSL:
                    [html]<pre>
                    <xsl:value-of select="myDisco unt:GetAllData( )" />
                    </pre>
                    [/html]

                    Please let me know the result.

                    Comment

                    • sani723
                      New Member
                      • Feb 2007
                      • 117

                      #11
                      not working, still same result

                      Comment

                      • dorinbogdan
                        Recognized Expert Contributor
                        • Feb 2007
                        • 839

                        #12
                        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.

                        Comment

                        • dorinbogdan
                          Recognized Expert Contributor
                          • Feb 2007
                          • 839

                          #13
                          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.

                          Comment

                          • dorinbogdan
                            Recognized Expert Contributor
                            • Feb 2007
                            • 839

                            #14
                            Hi,
                            Did you succeed to solve the problem ?
                            If yes, please let me know, in order to close the thread.
                            Thanks,
                            Dorin.

                            Comment

                            • sani723
                              New Member
                              • Feb 2007
                              • 117

                              #15
                              no, not yet

                              Comment

                              Working...