How to display XML into HTML Format

There are two ways to display XML content into HTML format.

1. Create  xsl file and add the reference of xsl file into xml file as shown below

“Test.xsl ”
<?xml version=”1.0″ encoding=”utf-8″?>

<xsl:stylesheet version=”1.0″
    xmlns:xsl=”http://www.w3.org/1999/XSL/Transform” >
<xsl:variable name =”HeaderNode” select=”Questionnaire/HeaderTbl”></xsl:variable>
<xsl:variable name =”StringTBLNode” select=”Questionnaire/StringTbl”></xsl:variable>
<xsl:template match=”/”>
…………………
………………..
</xsl:template>
</xsl:stylesheet>

Adding reference in xml file
<?xml version=”1.0″ encoding=”ISO-8859-1″?>
<?xml-stylesheet type=”text/xsl” href=”cdcatalog.xsl”?>
<rootNode>
………………………………………..
………… xml content………………
………………………………………..
………………………………………..

</rootNode>

2. Create the following HTML file and replace xsl and xml file names into it

<html>
<head>
<script>
var XMLDoc,XSLDoc

function load()
{
XMLDoc = new ActiveXObject(‘Microsoft.XMLDOM’);XMLDoc.async=true;XMLDoc.onreadystatechange=function(){if(XMLDoc.readyState==4){ loadXSL() }};
XMLDoc.load(‘defaultvalue.xml‘)
}

function loadXSL()
{
XSLDoc = new ActiveXObject(‘Microsoft.XMLDOM’);XSLDoc.async=true;      XSLDoc.onreadystatechange=function()
 {
  if(XMLDoc.readyState==4)
  {
     SetPrview()
   }
  };
  XSLDoc.load(‘Test.xsl‘)
}

function SetPrview()
{
 if(XSLDoc.readyState==4)
 {
    document.write(XMLDoc.transformNode(XSLDoc))
  }
}
</script>
</head>
<body onload=’load()’>
</body>
</html>

Continue ReadingHow to display XML into HTML Format