Loading data from a XML file in asp.net

How to display data from an xml file using xslt and asp.net

Following lines of code will give you an insight of reading data from an xml file and applying your formats and styles using XSLT

Here's a xml file showing categories of products

<?xml version="1.0" encoding="utf-8" ?>

<category pid='1' name='Men'>
<subcat prefid="11">Short sleeves</subcat>

<subcat prefid="12">Long Sleeves</subcat>
<subcat prefid="13">Tanks</subcat>
<subcat prefid="14">Sleeveless</subcat>
<category pid="2" name="Ladies" >
<subcat prefid= "21"> Short sleeves </subcat>

<subcat prefid="22"> Long Sleeves </subcat>
<subcat prefid="23"> Tanks </subcat>
<category pid="3" name="Athletic" >
<subcat prefid= "31"> Short sleeves </subcat>

<subcat prefid="32"> Long Sleeves </subcat>
<subcat prefid="33"> Tanks </subcat>


Here is another file showing the how thjis file needs to be presented

<?xml version="1.0"?>
<!-- This is a non-standard style sheet designed just for
Internet Explorer. It will not work with any standards
compliant XSLT processor. -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
<xsl:output method="html"/>

<xsl:template match="category">
<table width="50%" columns="2">
<xsl:variable name="category" select="@pid" />
<xsl:value-of select="@name"/>
<xsl:attribute name="SRC">
<xsl:value-of select="@img" />
<xsl:attribute name="ALT">
<xsl:value-of select="@alt" />



<xsl:template match="/categories/category/subcat">


This is how the code will be calling the data and presentation together in an ASP.net file

<asp:Xml id="Xml1" runat="server" TransformSource="style.xslt" DocumentSource="categories.xml"></asp:Xml>


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: