DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Display XML data in HTML

  1. #1
    Join Date
    Feb 2011
    Posts
    1

    Display XML data in HTML

    I have to display XML File to HTML.

    I have to count the node name start with log*,
    List the value of Prp name=nameof root in table
    Count the prp name= status by value wise (value will be 0, 1 and 2)

    See the below xml code prp element. I have to fetch those values and display in html. Guide me.

    Xml File
    <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
    <!DOCTYPE Nodes (View Source for full doctype...)>
    - <Nodes version="1">
    - <Node name="root">
    - <Node name="folders">
    <Node name="folders" />
    </Node>
    - <Node name="logs">
    - <Node name="log0">
    <Prp name="caption" type="S" value="" />
    <Prp name="datetime" type="D" value="40555.8125774653" />
    <Prp name="description" type="S" value="" />
    <Prp name="index" type="I" value="0" />
    <Prp name="key" type="S" value="{D57398B2-88CC-4117-A845-A7EC05154B10}" />
    <Prp name="nameofroot" type="S" value="ProjectTestItem4" />
    <Prp name="relpath" type="S" value="1_12_2011_7_30 PM_06_584\Description.tcLog" />
    <Prp name="status" type="I" value="2" />
    </Node>
    - <Node name="log1">
    <Prp name="caption" type="S" value="" />
    <Prp name="datetime" type="D" value="40555.8170275579" />
    <Prp name="description" type="S" value="" />
    <Prp name="index" type="I" value="1" />
    <Prp name="key" type="S" value="{AF25C22C-3D93-4589-AB5B-F1228DBB5F2B}" />
    <Prp name="nameofroot" type="S" value="Script Test Log [ExportLog\ExportLog]" />
    <Prp name="relpath" type="S" value="1_12_2011_7_36 PM_31_181\Description.tcLog" />
    <Prp name="status" type="I" value="0" />
    </Node>
    - <Node name="log2">
    <Prp name="caption" type="S" value="" />
    <Prp name="datetime" type="D" value="40555.8415466551" />
    <Prp name="description" type="S" value="" />
    <Prp name="index" type="I" value="2" />
    <Prp name="key" type="S" value="{A4AF26BE-E4CB-41B6-8218-501A30E3F69F}" />
    <Prp name="nameofroot" type="S" value="Script Test Log [ExportLog\ExportLog]" />
    <Prp name="relpath" type="S" value="1_12_2011_8_11 PM_49_631\Description.tcLog" />
    <Prp name="status" type="I" value="0" />
    </Node>
    </Node>
    <Prp name="signature" type="S" value="{681DCC69-A39F-4C4D-8E7D-B2D9362FAF4F}" />
    <Prp name="version" type="S" value="7.0" />
    </Node>
    </Nodes>

  2. #2
    Join Date
    May 2009
    Posts
    60
    Hello
    use predikat as if construct
    eg.
    Node[@name='logs'] means alle Node with attribut

    @name=logs are select

    with mode you can controll which template will select
    eg.

    xsl:apply-templates select="Prp" mode="description"

    xsl:template match="Prp[@name='description']" mode="description"
    xml testdata
    Code:
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <Nodes version="1">
    	<Node name="root">
    		<Node name="folders">
    			<Node name="folders"/>
    		</Node>
    		<Node name="logs">
    			<Node name="log0">
    				<Prp name="caption" type="S" value=""/>
    				<Prp name="datetime" type="D" value="40555.8125774653"/>
    				<Prp name="description" type="S" value=""/>
    				<Prp name="index" type="I" value="0"/>
    				<Prp name="key" type="S" value="{D57398B2-88CC-4117-A845-A7EC05154B10}"/>
    				<Prp name="nameofroot" type="S" value="ProjectTestItem4"/>
    				<Prp name="relpath" type="S" value="1_12_2011_7_30 PM_06_584\Description.tcLog"/>
    				<Prp name="status" type="I" value="2"/>
    			</Node>
    			<Node name="log1">
    				<Prp name="caption" type="S" value=""/>
    				<Prp name="datetime" type="D" value="40555.8170275579"/>
    				<Prp name="description" type="S" value=""/>
    				<Prp name="index" type="I" value="1"/>
    				<Prp name="key" type="S" value="{AF25C22C-3D93-4589-AB5B-F1228DBB5F2B}"/>
    				<Prp name="nameofroot" type="S" value="Script Test Log [ExportLog\ExportLog]"/>
    				<Prp name="relpath" type="S" value="1_12_2011_7_36 PM_31_181\Description.tcLog"/>
    				<Prp name="status" type="I" value="0"/>
    			</Node>
    			<Node name="log2">
    				<Prp name="caption" type="S" value=""/>
    				<Prp name="datetime" type="D" value="40555.8415466551"/>
    				<Prp name="description" type="S" value=""/>
    				<Prp name="index" type="I" value="2"/>
    				<Prp name="key" type="S" value="{A4AF26BE-E4CB-41B6-8218-501A30E3F69F}"/>
    				<Prp name="nameofroot" type="S" value="Script Test Log [ExportLog\ExportLog]"/>
    				<Prp name="relpath" type="S" value="1_12_2011_8_11 PM_49_631\Description.tcLog"/>
    				<Prp name="status" type="I" value="0"/>
    			</Node>
    		</Node>
    		<Prp name="signature" type="S" value="{681DCC69-A39F-4C4D-8E7D-B2D9362FAF4F}"/>
    		<Prp name="version" type="S" value="7.0"/>
    	</Node>
    </Nodes>
    xsl
    Code:
    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    	<xsl:output indent="yes" method="html"/>
    	<xsl:template match="/">
    		<html>
    		<style>
    		table{border="2px solid black"
    		}
    		td{border="2px solid black"
    		}
    		.all{border="2px solid red"
    		}
    		.status{border="2px solid blue"
    		}
    		.description{border="2px solid green"
    		}
    		</style>
    			<body>
    			</body>
    			<xsl:apply-templates select="Nodes"/>
    		</html>
    	</xsl:template>
    	<xsl:template match="Nodes">
    		<table >
    		<tr>
    		<th>Log</th><th>Description</th><th>Status</th><th>Type</th><th>Value</th>
    		</tr>
    			<xsl:apply-templates select="//Node[@name='logs']" mode="logs"/>
    		</table>
    	</xsl:template>
    	<xsl:template match="Node" mode="logs">
    		<xsl:apply-templates select="Node"/>
    	</xsl:template>
    	<xsl:template match="Node">
    		<tr>
    			<td>
    				<xsl:value-of select="concat(@name,' ',local-name(.),' ',position())"/>
    			</td>
    			<!-- choose which Information you wanted -->
    			<xsl:apply-templates select="Prp" mode="description"/>
    			<xsl:apply-templates select="Prp" mode="status"/>
    			<xsl:apply-templates select="Prp" mode="all"/>
    
    		</tr>
    	</xsl:template>
    	<xsl:template match="Prp[@name='description']" mode="description">
    		<td class="description">
    			<xsl:value-of select="@name"/>
    		</td>
    		
    	</xsl:template>
    	<xsl:template match="Prp[@name='status']" mode="status">
    		<td class="status">
    			<xsl:value-of select="@name"/>
    		</td>
    		<td class="status">
    		<xsl:value-of select="@type"/>
    		</td>
    		<td class="status">
    		<xsl:value-of select="@value"/>
    		</td>
    	</xsl:template>
    	<xsl:template match="Prp" mode="all">
    		<td class="all">
    			<xsl:value-of select="@name"/>
    		</td>
    		<td class="all">
    		<xsl:value-of select="@type"/>
    		</td>
    		<td class="all">
    		<xsl:value-of select="@value"/>
    		</td>
    	</xsl:template>
    
    </xsl:stylesheet>
    result
    Code:
    <html>
      <style>
    		table{border="2px solid black"
    		}
    		td{border="2px solid black"
    		}
    		.all{border="2px solid red"
    		}
    		.status{border="2px solid blue"
    		}
    		.description{border="2px solid green"
    		}
    		
      </style>
      <body></body>
      <table>
        <tr>
          <th>Log</th>
          <th>Description</th>
          <th>Status</th>
          <th>Type</th>
          <th>Value</th>
        </tr>
        <tr>
          <td>log0 Node 1</td>
          <td class="description">description</td>
          <td class="status">status</td>
          <td class="status">I</td>
          <td class="status">2</td>
          <td class="all">caption</td>
          <td class="all">S</td>
          <td class="all"></td>
          <td class="all">datetime</td>
          <td class="all">D</td>
          <td class="all">40555.8125774653</td>
          <td class="all">description</td>
          <td class="all">S</td>
          <td class="all"></td>
          <td class="all">index</td>
          <td class="all">I</td>
          <td class="all">0</td>
          <td class="all">key</td>
          <td class="all">S</td>
          <td class="all">{D57398B2-88CC-4117-A845-A7EC05154B10}</td>
          <td class="all">nameofroot</td>
          <td class="all">S</td>
          <td class="all">ProjectTestItem4</td>
          <td class="all">relpath</td>
          <td class="all">S</td>
          <td class="all">1_12_2011_7_30 PM_06_584\Description.tcLog</td>
          <td class="all">status</td>
          <td class="all">I</td>
          <td class="all">2</td>
        </tr>
        <tr>
          <td>log1 Node 2</td>
          <td class="description">description</td>
          <td class="status">status</td>
          <td class="status">I</td>
          <td class="status">0</td>
          <td class="all">caption</td>
          <td class="all">S</td>
          <td class="all"></td>
          <td class="all">datetime</td>
          <td class="all">D</td>
          <td class="all">40555.8170275579</td>
          <td class="all">description</td>
          <td class="all">S</td>
          <td class="all"></td>
          <td class="all">index</td>
          <td class="all">I</td>
          <td class="all">1</td>
          <td class="all">key</td>
          <td class="all">S</td>
          <td class="all">{AF25C22C-3D93-4589-AB5B-F1228DBB5F2B}</td>
          <td class="all">nameofroot</td>
          <td class="all">S</td>
          <td class="all">Script Test Log [ExportLog\ExportLog]</td>
          <td class="all">relpath</td>
          <td class="all">S</td>
          <td class="all">1_12_2011_7_36 PM_31_181\Description.tcLog</td>
          <td class="all">status</td>
          <td class="all">I</td>
          <td class="all">0</td>
        </tr>
        <tr>
          <td>log2 Node 3</td>
          <td class="description">description</td>
          <td class="status">status</td>
          <td class="status">I</td>
          <td class="status">0</td>
          <td class="all">caption</td>
          <td class="all">S</td>
          <td class="all"></td>
          <td class="all">datetime</td>
          <td class="all">D</td>
          <td class="all">40555.8415466551</td>
          <td class="all">description</td>
          <td class="all">S</td>
          <td class="all"></td>
          <td class="all">index</td>
          <td class="all">I</td>
          <td class="all">2</td>
          <td class="all">key</td>
          <td class="all">S</td>
          <td class="all">{A4AF26BE-E4CB-41B6-8218-501A30E3F69F}</td>
          <td class="all">nameofroot</td>
          <td class="all">S</td>
          <td class="all">Script Test Log [ExportLog\ExportLog]</td>
          <td class="all">relpath</td>
          <td class="all">S</td>
          <td class="all">1_12_2011_8_11 PM_49_631\Description.tcLog</td>
          <td class="all">status</td>
          <td class="all">I</td>
          <td class="all">0</td>
        </tr>
      </table>
    </html>

Similar Threads

  1. Replies: 0
    Last Post: 02-16-2009, 01:02 AM
  2. Xml + xsl = html 4 email ??
    By Complete in forum XML
    Replies: 0
    Last Post: 12-12-2008, 09:18 AM
  3. XML files vs Database
    By Mansoor in forum XML
    Replies: 8
    Last Post: 08-23-2002, 04:35 PM
  4. grouping xml data into sections int html
    By Ralph Carrasquillo in forum XML
    Replies: 0
    Last Post: 07-19-2001, 09:48 AM
  5. Is XML worth studying and using?
    By Mike Dubin in forum XML
    Replies: 3
    Last Post: 01-03-2001, 03:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center