Results 1 to 5 of 5

Thread: How to Display XML with XSLT?

  1. #1
    Join Date
    Jul 2006
    Posts
    182

    How to Display XML with XSLT?

    Hi Friends,
    I have just started working with an assignment. In that I've been given a sample XML file and an XSLT file which will apparently transform the XML into something with a meaningful layout. Also the coding should be suitable for displaying in a browser or printing. Now I don't know how to display that in XLST. Does anyone know how to Display XML with XSLT? Please help me as soon as you can ..!!!
    "Yea though I walk through the valley of the shadow of death... I will fear no evil." -Psalms 23

    K8N Diamond Plus (BIOS v1.2)
    AMD Athlon 64 X2 4400+
    Antec TruControl 550W
    NVidia GeForce 7900GT (NGO v1.8466 BETA)
    OCZ Platinum 2x1GB (2-3-2-5)
    SATA: WD740
    PATA: 2xWD2500, WD1200, NEC DVD/RW

  2. #2
    Join Date
    Mar 2008
    Posts
    672

    Re: How to Display XML with XSLT?

    I know how to display XML with XLST file using a Delphi app. I have given you an example below. In that example XMLContent is the XML you will be receiving and XSLContent is the XSLT. These are used to produce HTML pages from XML document templates. You will get the Output, whatever the XSLT generates. For doing this only the Delphi XML parser is used and no third party components are needed in this process. The following is the code for same :
    Code:
    Uses
      XMLFi, XMLIntf;
    
    function Transform(XMLContent : string; XSLContent : string) : WideString;
    var
      XML : IXMLFile;
      XSL : IXMLFile;
    begin
    
      XML := LoadXMLData(XMLContent);
      XSL := LoadXMLData(XSLContent);
    
      XML.DocumentElement.TransformNode(XSL.DocumentElement, Result)
    
    end;

  3. #3
    Join Date
    Mar 2008
    Posts
    349

    Re: How to Display XML with XSLT?

    XML content is mixed when text and attributes are both present inside an element. With XML we can use any tags we want, and the meaning of these tags are not automatically understood by the browser. XML attributes can be thought of as HTML element attributes, but in the case of XML, attributes and their values may be defined. The <title> element has mixed content in the following example :
    Code:
    <?xml version="1.0"?>
    <books>
          <book> 
                    <title ISBN="0321174582" author="Sudesh Rawat">
                    OpenGL Programming Guide Fourth Edition</title>  
                    <publisher>Addison-Wesley</publisher>
                    <year>2007</year>
         </book>
       <book>
                 <title ISBN="0849374982" author="Gerald Farin">
                 Information about Programming</title>
                 <publisher>International Press</publisher>
                 <year>2008</year>
        </book>
       <book>
                 <title ISBN="1558606639" author="David Hogers">
                 Ancient Monuments</title>
                 <publisher>Academic Press</publisher>
                 <year>2006</year>
         </book>
       <book>
                 <title ISBN="1568810867" author="Stephen Kiuynd">
                 Geometries Perpesctive</title>
                 <publisher>Sapna Printers</publisher>
                 <year>2006</year>
       </book>
    </books>

  4. #4
    Join Date
    Nov 2008
    Posts
    1,192

    Re: How to Display XML with XSLT?

    I used an MSXML library to do the XSLT transformation in Delphi. By doing that I have generated HTML from XML via XSLT, and displayed it using an ActiveX Web Browser (i.e. Internet Explorer) control on a pane in our application. You can manually edit an XML file, and add in a directive to get it to display using a specific XSLT, if this is your first time working with XSLT. When you open the XML in Firefox after the edit, the XSLT will be applied, and it will show you what will be the output of your MSXML calls. You can add the following line to XML :
    Code:
    <?xml-stylesheet type="trial/xsl" href="StyleSheet.xsl"?>

  5. #5
    Join Date
    Aug 2006
    Posts
    227

    Re: How to Display XML with XSLT?

    For can display XML with XSLT or in simple words you can say that with XSLT you can transform an XML document into HTML. XSLT is the recommended style sheet language of XML. If you want to display XML with XSLT, I have provided some coding that can help you. Here is the coding for XML :
    Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!-- Edited by XMLSpy® -->
    <breakfast_menu>
    	<food>
    		<name>Italian Pasta</name>
    		<price>$14.95</price>
    		<calories>920</calories>
    	</food>
    	<food>
    		<name>Strawberry Ice-Cream</name>
    		<price>$7.95</price>
    		<calories>457</calories>
    	</food>
    	<food>
    		<name>Chinese Noodles</name>
    		<price>$8.95</price>
    		<calories>750</calories>
    	</food>
    	<food>
    		<name>French Toast</name>
    		<price>$4.50</price>
    		<calories>600</calories>
    	</food>
    	<food>
    		<name>Homestyle Breakfast</name>
    		<price>$6.95</price>
    		<calories>950</calories>
    	</food>
    </breakfast_menu>
    And the following is the coding for XSLT :
    HTML Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <html xsl:version="1.0" xmlns:xsl="http://www.techarena.in/2003/XSL/Transform" xmlns="http://www.techarena.in/2003/xhtml">
      <body style="font-family:Arial;font-size:12pt;background-color:#EEEEEE">
        <xsl:for-each select="breakfast_menu/food">
          <div style="background-color:teal;color:white;padding:4px">
            <span style="font-weight:bold"><xsl:value-of select="name"/></span>
            - <xsl:value-of select="price"/>
          </div>
          <div style="margin-left:20px;margin-bottom:1em;font-size:10pt">
            <xsl:value-of select="description"/>
            <span style="font-style:italic">
              <xsl:value-of select="calories"/> (calories per serving)
            </span>
          </div>
        </xsl:for-each>
      </body>
    </html>
    I do to dead flowers what people at morgues do to dead people. Suck all the moisture out, dip them in plastic, paint them up pretty and put them in a nice frame.

Similar Threads

  1. Display a XML and Transform It With XSLT in Java
    By Level8 in forum Software Development
    Replies: 4
    Last Post: 25-02-2010, 10:20 PM
  2. Use of XSLT
    By Mithun Seth in forum Software Development
    Replies: 5
    Last Post: 13-02-2010, 01:16 PM
  3. Is XSL and XSLT are same
    By Crespin in forum Software Development
    Replies: 3
    Last Post: 21-11-2009, 05:58 AM
  4. problem with xml et xslt
    By manjava in forum Software Development
    Replies: 0
    Last Post: 28-12-2008, 05:26 PM
  5. XML ,XSL, XSLT problem
    By MarceloQuad in forum Software Development
    Replies: 2
    Last Post: 25-10-2008, 04:26 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,568,029.03940 seconds with 17 queries