xslt with xml control in asp.net - asp.net

my xml file name is product_file.xml and i have an xslt file , i am using a xml control in my webpage by binding xml & xslt files to the control but i am not getting the output properly. It showing only header multiple times
<?xml version="1.0" encoding="utf-8" ?>
<productlist>
<product>
<itemnumber>1</itemnumber>
<name>Staple Superior Men’s Jacket</name>
<description>The Staple Superior T-bone PU Jacket is classic hood with a drawstring fastening, long and a zip up front fastening.</description>
<color>BLACK</color>
<image>Staplesuperior1.gif</image>
<price>$140</price>
<size>69</size>
<quantity>1</quantity>
<category>Men</category>
</product>
<product>
<itemnumber>2</itemnumber>
<name>Afends Mens t-shirt</name>
<description>The Afends Thrash For Cash Raglan Tee has a scooped hemline, a 100% cotton composition, and a regular fit.</description>
<color>Beach Heather & Black</color>
<image>Afends1.gif</image>
<price>$90</price>
<size>80</size>
<quantity>1</quantity>
<category>Men</category>
</product>
<product>
<itemnumber>3</itemnumber>
<name>Wrangler Men Blue Vegas Skinny Fit Jeans</name>
<description>Blue 5 pocket jeans, stretchable, has a zip fly with buttoned closure in front, 2 scoop pockets at sides</description>
<image>Wrangler1.gif</image>
<color>BLUE</color>
<price>$125</price>
<size>32</size>
<quantity>1</quantity>
<category>Men</category>
</product>
<product>
<itemnumber>4</itemnumber>
<name>Roadster Women Top</name>
<description>Black top, knit, V neck, short extended sleeves, lattice like fabric manipulation detail at shoulders</description>
<color>BLACK</color>
<image>Roadster.gif</image>
<price>$55</price>
<size>Small</size>
<quantity>1</quantity>
<category>Women</category>
</product>
and my xslt file is
<xsl:template match="product">
<html>
<head>
<title>Products XSLT Demo</title>
</head>
<body>
<h2>Products Information</h2>
<br/>
<!--<xsl:copy>
<xsl:apply-templates select="#* | node()"/>
</xsl:copy>-->
<table bgcolor="#008BE7" border="1">
<xsl:for-each select="itemnumber">
<tr>
<td>Item Number</td>
<td>
<xsl:value-of select="itemnumber"/>
</td>
</tr>
<tr> <td>name</td>
<td>
<xsl:value-of select="name"/>
</td>
</tr>
<tr>
<td>description</td>
<td>
<xsl:value-of select="description"/>
</td>
</tr>
<tr>
<td>color</td>
<td>
<xsl:value-of select="color"/>
</td>
</tr>
<tr>
<td>price</td>
<td>
<xsl:value-of select="price"/>
</td>
</tr>
<tr>
<td>size</td>
<td>
<xsl:value-of select="size"/>
</td>
</tr>
<tr> <td>quantity</td>
<td>
<xsl:value-of select="quantity"/>
</td>
</tr>
<tr>
<td>category</td>
<td>
<xsl:value-of select="category"/>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
now the error is the foreach expression not working so the ouput showing only heading multiple times

This seems to be working for me. changing the templatematch to productlist and foreach to product
<xsl:template match="productlist">
<html>
<head>
<title>Products XSLT Demo</title>
</head>
<body>
<h2>Products Information</h2>
<br/>
<!--<xsl:copy>
<xsl:apply-templates select="#* | node()"/>
</xsl:copy>-->
<table bgcolor="#008BE7" border="1">
<xsl:for-each select="product">
<tr>
<td>Item Number</td>
<td>
<xsl:value-of select="itemnumber"/>
</td>
</tr>
<tr> <td>name</td>
<td>
<xsl:value-of select="name"/>
</td>
</tr>
<tr>
<td>description</td>
<td>
<xsl:value-of select="description"/>
</td>
</tr>
<tr>
<td>color</td>
<td>
<xsl:value-of select="color"/>
</td>
</tr>
<tr>
<td>price</td>
<td>
<xsl:value-of select="price"/>
</td>
</tr>
<tr>
<td>size</td>
<td>
<xsl:value-of select="size"/>
</td>
</tr>
<tr> <td>quantity</td>
<td>
<xsl:value-of select="quantity"/>
</td>
</tr>
<tr>
<td>category</td>
<td>
<xsl:value-of select="category"/>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>

Change the foreach to
<xsl:for-each select=".">

Related

XSLT stylesheet detects table elements but doesn't show them

I want to output the names, domain and usage of a database where its version is equal to 20i. I have created a stylesheet that does this - when I load my xml, it detects that I have an element matching my requirements in the table, but doesn't actually show them. No idea what I'm doing wrong!
XML:
<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="xrt.xsl"?>
<Inventory>
<DatabaseName>
<GlobalName>Tom</GlobalName>
<Function>production</Function>
<Domain>tom.info</Domain>
<Administrator EmailAlias="xrichards" Extension="221">Xavier Richards</Administrator>
<Attributes Type="Production" Version="20ix"/>
<Comments>
...
</Comments>
<Usage>
500
</Usage>
</DatabaseName>
<DatabaseName>
<GlobalName>Ricardo</GlobalName>
<Function>production</Function>
<Domain>tom.info</Domain>
<Administrator EmailAlias="xrichards" Extension="221">Xavier Richards</Administrator>
<Attributes Type="Production" Version="20i"/>
<Comments>
...
</Comments>
<Usage>
500
</Usage>
</DatabaseName>
<WebserverName>
<GlobalName>Jim</GlobalName>
<Function>distribution</Function>
<Domain>jim1235.com</Domain>
<Administrator EmailAlias="rkarvani" Extension="134237">Richard Karvani</Administrator>
<Administrator EmailAlias="stones" Extension="222237">Steve Jones</Administrator>
<Attributes Type="Production" Version="20i"/>
<Comments>
...
</Comments>
<Usage>
1200
</Usage>
</WebserverName>
</Inventory>
XSLT Document:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h1>My Server List</h1>
<h2>Database Servers</h2>
<xsl:apply-templates select="Inventory/DatabaseName" />
<h2>Webservers</h2>
<xsl:apply-templates select="Inventory/WebserverName" />
</body>
</html>
</xsl:template>
<xsl:template match="DatabaseName">
<table border="1">
<tr>
<th>Name</th>
<th>Domain</th>
<th>Usage</th>
</tr>
<xsl:for-each select="Attributes[#Version='20i']">
<tr>
<td><xsl:value-of select="GlobalName"/></td>
<td><xsl:value-of select="Domain"/></td>
<td><xsl:value-of select="Usage"/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
<xsl:template match="WebserverName">
<table border="1">
<tr>
<th>Name</th>
<th>Domain</th>
<th>Usage</th>
</tr>
<xsl:for-each select="Attributes[#Version='20i']">
<tr>
<td><xsl:value-of select="GlobalName"/></td>
<td><xsl:value-of select="Domain"/></td>
<td><xsl:value-of select="Usage"/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
I think you want to put the condition about that version into the apply-templates and move the table creation to the another template:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h1>My Server List</h1>
<h2>Database Servers</h2>
<table border="1">
<tr>
<th>Name</th>
<th>Domain</th>
<th>Usage</th>
</tr>
<xsl:apply-templates select="Inventory/DatabaseName[Attributes[#Version='20i']]" />
</table>
<h2>Webservers</h2>
<table border="1">
<tr>
<th>Name</th>
<th>Domain</th>
<th>Usage</th>
</tr>
<xsl:apply-templates select="Inventory/WebserverName[Attributes[#Version='20i']]" />
</table>
</body>
</html>
</xsl:template>
<xsl:template match="DatabaseName">
<tr>
<td><xsl:value-of select="GlobalName"/></td>
<td><xsl:value-of select="Domain"/></td>
<td><xsl:value-of select="Usage"/></td>
</tr>
</xsl:template>
<xsl:template match="WebserverName">
<tr>
<td><xsl:value-of select="GlobalName"/></td>
<td><xsl:value-of select="Domain"/></td>
<td><xsl:value-of select="Usage"/></td>
</tr>
</xsl:template>
</xsl:stylesheet>

XML - Putting images into .xsl

I have a "blog" made with XML and XLST.
This is the format of the blog:
<post id="1" category="Miscellaneous">
<ptitle>MiG-21</ptitle>
<psubtitle>Mikoyan-Gurevich MiG-21</psubtitle>
<image></image>
<author> Brian Livori </author>
<date> 11/10/2012 </date>
<par> The Mikoyan-Gurevich MiG-21 (Russian: Микоян и Гуревич МиГ-21; NATO reporting name: Fishbed) is a supersonic jet fighter aircraft, designed by the Mikoyan-Gurevich Design Bureau in the Soviet Union. It was popularly nicknamed "balalaika", from the aircraft's planform-view resemblance to the Russian stringed musical instrument or ołówek (English: pencil) by Polish pilots due to the shape of its fuselage.[2]
Early versions are considered second-generation jet fighters, while later versions are considered to be third-generation jet fighters. Some 50 countries over four continents have flown the MiG-21, and it still serves many nations a half-century after its maiden flight. The fighter made aviation records. At least by name, it is the most-produced supersonic jet aircraft in aviation history and the most-produced combat aircraft since the Korean War, and it had the longest production run of a combat aircraft (1959 to 1985 over all variants).
</par>
<source>http://en.wikipedia.org/wiki/Mikoyan-Gurevich_MiG-21</source>
<comments>dsgsdg</comments>
</post>
<post id="2" category="Miscellaneous">
<ptitle>MiG-21</ptitle>
<psubtitle>Mikoyan-Gurevich MiG-21</psubtitle>
<image></image>
<author> Brian Livori </author>
<date> 11/10/2012 </date>
<par> The Mikoyan-Gurevich MiG-21 (Russian: Микоян и Гуревич МиГ-21; NATO reporting name: Fishbed) is a supersonic jet fighter aircraft, designed by the Mikoyan-Gurevich Design Bureau in the Soviet Union. It was popularly nicknamed "balalaika", from the aircraft's planform-view resemblance to the Russian stringed musical instrument or ołówek (English: pencil) by Polish pilots due to the shape of its fuselage.[2]
Early versions are considered second-generation jet fighters, while later versions are considered to be third-generation jet fighters. Some 50 countries over four continents have flown the MiG-21, and it still serves many nations a half-century after its maiden flight. The fighter made aviation records. At least by name, it is the most-produced supersonic jet aircraft in aviation history and the most-produced combat aircraft since the Korean War, and it had the longest production run of a combat aircraft (1959 to 1985 over all variants).
</par>
<source>http://en.wikipedia.org/wiki/Mikoyan-Gurevich_MiG-21</source>
<comments>dsgsdg</comments>
</post>
I would like to insert an image for each blog post.
How can I do this?
This is my .xls file:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match ="/">
<html>
<body>
<table align="center" >
<tr bgcolor="C77838">
<th>Brian's Blog </th>
<th>About</th>
<th>Contact</th>
</tr>
</table>
<table align="center" bgcolor="1D6135">
<tr align="center">
<xsl:element name="img" >
<xsl:attribute name="border">0</xsl:attribute>
<xsl:attribute name="src">images/banner.jpg</xsl:attribute>
<xsl:attribute name="alt">Banner</xsl:attribute>
</xsl:element>
</tr>
<tr align="center">
<h1>JET FIGHTERS</h1>
</tr>
</table>
<br></br><br></br>
<table >
<td width="10%" bgcolor="white"></td>
<td bgcolor="CC9933">
<xsl:for-each select="blog/post">
<tr bgcolor="FFFF99" ><td><xsl:value-of select="ptitle"/></td></tr>
<tr bgcolor="FFFFCC"><td><xsl:value-of select="psubtitle"/></td></tr><br></br><br></br>
<tr bgcolor="FFFFCC"><td><xsl:value-of select="image"/></td></tr>
<tr><td><xsl:value-of select="par"/></td></tr><br></br><br></br>
<tr bgcolor="D6D6B2"><td>Source: <xsl:value-of select="source"/></td></tr>
<br></br><tr bgcolor="FFFFCC">Posted on: <xsl:value-of select="date"/> by <xsl:value-of select="author"/></tr>
<br></br><tr bgcolor="FFFFCD">Comments: <xsl:value-of select="comments"/> by <xsl:value-of select="comments"/></tr>
<hr color="white"></hr>
</xsl:for-each>
</td>
<td width="10%" bgcolor="white"></td>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="list">
Images are element contents, apply a template to all image elements:
<xsl:apply-templates select="image"/>
Images are attribute values of an element, we do it differently:
<xsl:apply-templates select="image3"/>
</xsl:template>
<xsl:template match="image1">
<p> <img src="{#source}"/><br/><xsl:value-of select="."/> </p>
</xsl:template>
</xsl:stylesheet>
Assuming that the images' URLs are going to be contained in the <image> element and that the images should be omitted for <images> that are blank, I believe this is what you're trying to accomplish. Please clarify your question if not:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match ="/">
<html>
<body>
<table align="center" >
<tr bgcolor="C77838">
<th>Brian's Blog </th>
<th>About</th>
<th>Contact</th>
</tr>
</table>
<table align="center" bgcolor="1D6135">
<tr align="center">
<td>
<img border="0" src="images/banner.jpg" alt="Banner" />
</td>
</tr>
<tr align="center">
<td>
<h1>JET FIGHTERS</h1>
</td>
</tr>
</table>
<br />
<br />
<table >
<tr>
<td width="10%" bgcolor="white"></td>
<td bgcolor="CC9933">
<xsl:apply-templates select="blog/post" />
</td>
<td width="10%" bgcolor="white"></td>
</tr>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="post">
<table>
<tr bgcolor="FFFF99" >
<td>
<xsl:value-of select="ptitle"/>
</td>
</tr>
<tr bgcolor="FFFFCC">
<td>
<xsl:value-of select="psubtitle"/>
</td>
</tr>
<br></br>
<br></br>
<xsl:if test="normalize-space(image)">
<tr bgcolor="FFFFCC">
<td>
<xsl:apply-templates select="image"/>
</td>
</tr>
</xsl:if>
<tr>
<td>
<xsl:value-of select="par"/>
</td>
</tr>
<br />
<br />
<tr bgcolor="D6D6B2">
<td>
Source: <xsl:value-of select="source"/>
</td>
</tr>
<br></br>
<tr bgcolor="FFFFCC">
<td>
Posted on: <xsl:value-of select="date"/> by <xsl:value-of select="author"/>
</td>
</tr>
<br></br>
<tr bgcolor="FFFFCD">
<td>
Comments: <xsl:value-of select="comments"/> by <xsl:value-of select="comments"/>
</td>
</tr>
<hr color="white" />
</table>
</xsl:template>
<xsl:template match="image">
<p>
<img src="{.}"/>
<br/>
<xsl:value-of select="."/>
</p>
</xsl:template>
</xsl:stylesheet>
There are a lot of problems with your HTML. I cleaned up what I could, but there's a lot more to fix. You shouldn't be using tables for layout, but if you must do so, at the very least, you should not have <br/ >s and <hr />s directly below a table element, <td>s must be directly under <tr>s, and <tr>s must be directly below <table>s.

Refreshing the xml file through button

I am using an asp web application that has a tab. When I click on that tab, an xml file is read. That xml file has data in it. That xml file has a href pointing to an xslt file where I have written code for creating a table for displaying the xml data in the xml file in a presentable manner in the browser.
The user may change the data in the xml file or he may remove some data too, during runtime. I have included a refresh button in the xslt file. During runtime, if the user makes changes to the xml file, I wish to click on the refresh button to reflect the changes in the table in web page. I just want the xml file to be refreshed and the corresponding changes to be reflected in the web page.
How do I do this? I have uploaded my code below :
ASPX FILE
<%# Page Title="Home Page" Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="sampleapp._Default" %>
<%# Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
<html>
<head id="Head1" runat="server">
<meta http-equiv="Cache-Control" content="no-cache"/>
<meta http-equiv="Pragma" content="no-cache"/>
<meta http-equiv="Expires" content="0"/>
<title>VPGate Configuration</title>
<link rel="stylesheet" type="text/css" href="office2007.css"/>
<link rel="stylesheet" type="text/css" href="style002.css"/>
<script language="javascript" type="text/javascript">
function window.onload() {
try {
if (self != top)
self.parent.location = document.location;
}
catch (Exception) { }
}
</script>
</head>
<body>
<form id="form1" runat="server">
<telerik:RadScriptManager ID="RadScriptManager1" Runat="server">
</telerik:RadScriptManager>
<script type="text/javascript">
function OnClientTabSelected(sender, eventArgs) {
var tab = eventArgs.get_tab();
if (tab.get_tabs().get_count() > 0) {
tab.get_tabs().getTab(0).select();
//tab.get_tabs().getTab(0).click();
}
if (tab.get_text() == "Help") {
document.getElementById("helpframe").style.display = "inline";
document.getElementById("framebody").style.display = "none";
document.getElementById("framebody").src = "";
if (document.getElementById("helpframe").src == "")
document.getElementById("helpframe").src = "/help/ApplicationHelp.htm";
}
else {
document.getElementById("helpframe").style.display = "none";
document.getElementById("framebody").style.display = "inline";
}
}
function OnClientTabSelecting(sender, eventArgs) {
if (!formchk2()) {
eventArgs.set_cancel(true);
return false;
}
}
</script>
<telerik:RadTabStrip ID="tab1" runat="server" ShowBaseLine="True"
EnableEmbeddedSkins="False" ClickSelectedTab="True"
UnSelectChildren="True" SelectedIndex="3"
OnClientTabSelected="OnClientTabSelected" Skin="Office2007" style="margin-left: 29px;border-left-style:none;"
OnClientTabSelecting="OnClientTabSelecting">
<Tabs>
<telerik:RadTab Text="General" NavigateUrl="ShowXML.aspx?file=MMDiagnostics.xml" Target="framebody" Selected="true"></telerik:RadTab>
</Tabs>
</telerik:RadTabStrip>
<iframe id="framebody" name="framebody" runat="server"
style="border-left: thin solid #4173be; border-right: thin solid #4173be; border-bottom: thin solid #4173be; height:112%; width:100%; border-top-width:0px; border-top-color:White;
background-color:white; float:left;height:92.5%; width:97.4%; margin-left:9.5px;"
frameborder="0" scrolling="no">
</iframe>
</form>
</body>
</html>
XML FILE
<?xml-stylesheet type="text/xsl" href="MMDiagnostics.xslt"?>
<MediaMixer>
<Conference>
<Name>Test001</Name>
<ConfId>1000</ConfId>
<CompositeAddress>238.57.0.1</CompositeAddress>
<CompositePort>48000</CompositePort>
<CompositeSsrc>243324353</CompositeSsrc>
<NoOfParticipants>2</NoOfParticipants>
<Participant>
<ID1>80542151</ID1>
<ID2>0</ID2>
<ParticipantAddress>192.168.177.40</ParticipantAddress>
<ParticipantListeningPort>22000</ParticipantListeningPort>
<MMListeningPort>45000</MMListeningPort>
<SSRCFromParticipant>216541</SSRCFromParticipant>
<SSRCFromMM>56481</SSRCFromMM>
</Participant>
<Participant>
<ID1>80542151</ID1>
<ID2>harish</ID2>
<ParticipantAddress>192.168.177.40</ParticipantAddress>
<ParticipantListeningPort>22000</ParticipantListeningPort>
<MMListeningPort>45000</MMListeningPort>
<SSRCFromParticipant>216541</SSRCFromParticipant>
<SSRCFromMM>56481</SSRCFromMM>
</Participant>
<Participant>
<ID1>7825482</ID1>
<ID2>0</ID2>
<ParticipantAddress>192.168.177.22</ParticipantAddress>
<ParticipantListeningPort>22002</ParticipantListeningPort>
<MMListeningPort>45002</MMListeningPort>
<SSRCFromParticipant>3256</SSRCFromParticipant>
<SSRCFromMM>14822456</SSRCFromMM>
</Participant>
</Conference>
<Conference>
<Name>Test002</Name>
<ConfId>1002</ConfId>
<CompositeAddress>238.57.0.1</CompositeAddress>
<CompositePort>48005</CompositePort>
<CompositeSsrc>353324353</CompositeSsrc>
<NoOfParticipants>2</NoOfParticipants>
<Participant>
<ID1>70542151</ID1>
<ID2>0</ID2>
<ParticipantAddress>192.168.177.45</ParticipantAddress>
<ParticipantListeningPort>22004</ParticipantListeningPort>
<MMListeningPort>45004</MMListeningPort>
<SSRCFromParticipant>316541</SSRCFromParticipant>
<SSRCFromMM>26481</SSRCFromMM>
</Participant>
<Participant>
<ID1>70542151</ID1>
<ID2>0</ID2>
<ParticipantAddress>192.168.177.45</ParticipantAddress>
<ParticipantListeningPort>22004</ParticipantListeningPort>
<MMListeningPort>45004</MMListeningPort>
<SSRCFromParticipant>316541</SSRCFromParticipant>
<SSRCFromMM>26481</SSRCFromMM>
</Participant>
<Participant>
<ID1>70542151</ID1>
<ID2>0</ID2>
<ParticipantAddress>192.168.177.45</ParticipantAddress>
<ParticipantListeningPort>22004</ParticipantListeningPort>
<MMListeningPort>45004</MMListeningPort>
<SSRCFromParticipant>316541</SSRCFromParticipant>
<SSRCFromMM>26481</SSRCFromMM>
</Participant>
<Participant>
<ID1>70542151</ID1>
<ID2>0</ID2>
<ParticipantAddress>192.168.177.45</ParticipantAddress>
<ParticipantListeningPort>22004</ParticipantListeningPort>
<MMListeningPort>45004</MMListeningPort>
<SSRCFromParticipant>316541</SSRCFromParticipant>
<SSRCFromMM>26481</SSRCFromMM>
</Participant>
<Participant>
<ID1>70542151</ID1>
<ID2>0</ID2>
<ParticipantAddress>192.168.177.45</ParticipantAddress>
<ParticipantListeningPort>22004</ParticipantListeningPort>
<MMListeningPort>45004</MMListeningPort>
<SSRCFromParticipant>316541</SSRCFromParticipant>
<SSRCFromMM>26481</SSRCFromMM>
</Participant>
<Participant>
<ID1>5625482</ID1>
<ID2>0</ID2>
<ParticipantAddress>192.168.177.20</ParticipantAddress>
<ParticipantListeningPort>22006</ParticipantListeningPort>
<MMListeningPort>45006</MMListeningPort>
<SSRCFromParticipant>8256</SSRCFromParticipant>
<SSRCFromMM>41822456</SSRCFromMM>
</Participant>
</Conference>
</MediaMixer>
XSLT FILE
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<title>VPGate Media Mixer</title>
<meta http-equiv="expires" content="0"/>
<meta http-equiv="pragma" content="no-cache"/>
<meta http-equiv="cache-control" content="no-cache, must-revalidate"/>
<meta http-equiv="refresh" content="15"></meta>
<script src="/Common/common.js\" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="style001.css" />
<link rel="stylesheet" type="text/css" href="Grid.Default.css" />
</head>
<body class="WorkArea">
<div class="divSummaryHeader" id="SummaryHeader">
<h1>Media Mixer - VPGate</h1>
<xsl:for-each select="MMDiagnostics/Conference">
<h1>
Media Mixer - <xsl:value-of select="name"/>
</h1>
</xsl:for-each>
</div>
 
<div class="RadGrid RadGrid_Default" id="SummaryData" style="position:absolute;width:630px;overflow:auto">
<table border="0" class="rgMasterTable rgClipCells" cellspacing="0" cellpadding="0" >
<tr>
<input type="button" class="formEditBtn" id="SubBtn" value="Refresh" onclick="window.location=window.location;"/>
</tr>
<tr>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;" colspan="2">Conference</td>
</tr>
<tr>
<td>
<table border="0" class="rgMasterTable rgClipCells" cellspacing="0" cellpadding="0" >
<tr>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Name</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Conference Id</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Composite Address</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Composite Port</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Composite Ssrc</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">No Of Participants</td>
</tr>
<xsl:for-each select="MediaMixer/Conference">
<!--<xsl:sort select="Name"/>-->
<xsl:if test="(position() mod 2 = 0)">
<tr class="rgAltRow SummaryTableDataRow">
<td valign = "top">
<xsl:value-of select="Name"/>
</td>
<td valign = "top">
<xsl:value-of select="ConfId"/>
</td>
<td valign = "top">
<xsl:value-of select="CompositeAddress"/>
</td>
<td valign = "top">
<xsl:value-of select="CompositePort"/>
</td>
<td valign = "top">
<xsl:value-of select="CompositeSsrc"/>
</td>
<td valign = "top">
<xsl:value-of select="NoOfParticipants"/>
</td>
</tr>
</xsl:if>
<xsl:if test="(position() mod 2 = 1)">
<td bgcolor="#aaaaff">
<tr class="rgAltRow SummaryTableDataRow">
<td valign = "top">
<xsl:value-of select="Name"/>
</td>
<td valign = "top">
<xsl:value-of select="ConfId"/>
</td>
<td valign = "top">
<xsl:value-of select="CompositeAddress"/>
</td>
<td valign = "top">
<xsl:value-of select="CompositePort"/>
</td>
<td valign = "top">
<xsl:value-of select="CompositeSsrc"/>
</td>
<td valign = "top">
<xsl:value-of select="NoOfParticipants"/>
</td>
</tr>
</td>
</xsl:if>
</xsl:for-each>
</table>
</td>
</tr>
</table>
 
<table border="0" class="rgMasterTable rgClipCells" cellspacing="1" cellpadding="1" >
<tr>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;" colspan="2">Participant</td>
</tr>
<tr>
<td>
<table border="0" class="rgMasterTable rgClipCells" cellspacing="0" cellpadding="0" >
<tr>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">ID 1</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">ID 2</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Participant Address</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Participant Listening Port</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">MM Listening Port</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">SSRC From Participant</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">SSRC From MM</td>
</tr>
<xsl:for-each select="MediaMixer/Conference/Participant">
<xsl:if test="(position() mod 2 = 0)">
<tr class="rgAltRow SummaryTableDataRow">
<td valign = "top">
<xsl:value-of select="ID1"/>
</td>
<td valign = "top">
<xsl:value-of select="ID2"/>
</td>
<td valign = "top">
<xsl:value-of select="ParticipantAddress"/>
</td>
<td valign = "top">
<xsl:value-of select="ParticipantListeningPort"/>
</td>
<td valign = "top">
<xsl:value-of select="MMListeningPort"/>
</td>
<td valign = "top">
<xsl:value-of select="SSRCFromParticipant"/>
</td>
<td valign = "top">
<xsl:value-of select="SSRCFromMM"/>
</td>
</tr>
</xsl:if>
<xsl:if test="(position() mod 2 = 1)">
<td bgcolor="#aaaaff">
<tr class="rgAltRow SummaryTableDataRow">
<td valign = "top">
<xsl:value-of select="ID1"/>
</td>
<td valign = "top">
<xsl:value-of select="ID2"/>
</td>
<td valign = "top">
<xsl:value-of select="ParticipantAddress"/>
</td>
<td valign = "top">
<xsl:value-of select="ParticipantListeningPort"/>
</td>
<td valign = "top">
<xsl:value-of select="MMListeningPort"/>
</td>
<td valign = "top">
<xsl:value-of select="SSRCFromParticipant"/>
</td>
<td valign = "top">
<xsl:value-of select="SSRCFromMM"/>
</td>
</tr>
</td>
</xsl:if>
</xsl:for-each>
</table>
</td>
</tr>
</table>
 
<div style="display:none">
<iframe id="frameUpdate" name="frameUpdate" width="100%"></iframe>
</div>
</div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
You can set at the client side timer using setTimeout function.
Eeach time you can read the xml and check modified date
of the file. Or for example to set attribute in XML changedDate and to check it
each time.If it's changed from previous one you can refresh the xml .
So as I stated previously you can check modified data of xml or to set attribute "ModifiedDate" in XML .
When someone updates XML , he must change update the attribure.

xml data in upper-case

I have a xslt file that fetches data from a xml file and displays them accordingly. Some of the data in the xml file are in lower-case. Is there any way by which I can change it to upper-case inside the xslt while displaying it in the table? my xslt file is as given below:
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<title>VPGate Media Mixer</title>
<meta http-equiv="expires" content="0"/>
<meta http-equiv="pragma" content="no-cache"/>
<meta http-equiv="cache-control" content="no-cache, must-revalidate"/>
<meta http-equiv="refresh" content="15"></meta>
<script src="/Common/common.js\" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="style001.css" />
<link rel="stylesheet" type="text/css" href="Grid.Default.css" />
</head>
<body class="WorkArea">
<div class="divSummaryHeader" id="SummaryHeader">
<h1>Media Mixer - VPGate</h1>
<xsl:for-each select="MMDiagnostics/Conference">
<h1>
Media Mixer - <xsl:value-of select="name"/>
</h1>
</xsl:for-each>
</div>
 
<div class="RadGrid RadGrid_Default" id="SummaryData" style="position:absolute;width:810px;height:510px;overflow:auto">
<table border="0" class="rgMasterTable rgClipCells" cellspacing="0" cellpadding="0" >
<tr>
<input type="button" class="formEditBtn" id="SubBtn" value="Refresh" onclick="window.location=window.location;"/>
</tr>
<tr>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;" colspan="2">Conference Summary</td>
</tr>
<tr>
<td>
<table border="0" class="rgMasterTable rgClipCells" cellspacing="0" cellpadding="0" >
<tr>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Conference Name</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Conference ID</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Composite Address</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Composite Port</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Composite Ssrc</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">No Of Participants</td>
</tr>
<xsl:if test="MediaMixer!= ''">
<xsl:for-each select="MediaMixer/Conference">
<!--<xsl:sort select="Name"/>-->
<xsl:if test="Name !=''">
<xsl:if test="(position() mod 2 = 0)">
<tr class="rgAltRow SummaryTableDataRow">
<td valign = "top">
<xsl:value-of select="Name"/>
</td>
<td valign = "top">
<xsl:value-of select="ConfId"/>
</td>
<td valign = "top">
<xsl:value-of select="CompositeAddress"/>
</td>
<td valign = "top">
<xsl:value-of select="CompositePort"/>
</td>
<td valign = "top">
<xsl:value-of select="CompositeSsrc"/>
</td>
<td valign = "top">
<xsl:value-of select="NoOfParticipants"/>
</td>
</tr>
</xsl:if>
<xsl:if test="(position() mod 2 = 1)">
<td>
<tr class="rgRow SummaryTableDataRow">
<td valign = "top">
<xsl:value-of select="Name"/>
</td>
<td valign = "top">
<xsl:value-of select="ConfId"/>
</td>
<td valign = "top">
<xsl:value-of select="CompositeAddress"/>
</td>
<td valign = "top">
<xsl:value-of select="CompositePort"/>
</td>
<td valign = "top">
<xsl:value-of select="CompositeSsrc"/>
</td>
<td valign = "top">
<xsl:value-of select="NoOfParticipants"/>
</td>
</tr>
</td>
</xsl:if>
</xsl:if>
</xsl:for-each>
</xsl:if>
<xsl:if test="MediaMixer = ''">
<td valign = "top">
<xsl:text>No Data </xsl:text>
</td>
</xsl:if>
</table>
</td>
</tr>
</table>
 
<table border="0" class="rgMasterTable rgClipCells" cellspacing="1" cellpadding="1" >
<tr>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;" colspan="2">Conference Details</td>
</tr>
<tr>
<td>
<table border="0" class="rgMasterTable rgClipCells" cellspacing="0" cellpadding="0" >
<tr>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Conference Name</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Conference ID</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Participant ID 1</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Participant ID 2</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Participant Address</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">Participant Listening Port</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">MM Listening Port</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">SSRC From Participant</td>
<td class="rgHeader SummaryTableHdrRow" style="font-weight:bold;">SSRC From MM</td>
</tr>
<xsl:if test="MediaMixer!= ''">
<xsl:for-each select="MediaMixer/Conference">
<xsl:for-each select="Participant">
<xsl:if test="(position() mod 2 = 0)">
<tr class="rgAltRow SummaryTableDataRow">
<td valign = "top">
<xsl:value-of select="../Name"/>
</td>
<td valign = "top">
<xsl:value-of select="../ConfId"/>
</td>
<td valign = "top">
<xsl:variable name="text" select="'Upper'" />
<xsl:value-of select="translate($text, 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')" />
</td>
<td valign = "top">
<xsl:value-of select="ID2"/>
</td>
<td valign = "top">
<xsl:value-of select="ParticipantAddress"/>
</td>
<td valign = "top">
<xsl:value-of select="ParticipantListeningPort"/>
</td>
<td valign = "top">
<xsl:value-of select="MMListeningPort"/>
</td>
<td valign = "top">
<xsl:value-of select="SSRCFromParticipant"/>
</td>
<td valign = "top">
<xsl:value-of select="SSRCFromMM"/>
</td>
</tr>
</xsl:if>
<xsl:if test="(position() mod 2 = 1)">
<td>
<tr class="rgRow SummaryTableDataRow">
<td valign = "top">
<xsl:value-of select="../Name"/>
</td>
<td valign = "top">
<xsl:value-of select="../ConfId"/>
</td>
<td valign = "top">
<xsl:value-of select="ID1"/>
</td>
<td valign = "top">
<xsl:value-of select="ID2"/>
</td>
<td valign = "top">
<xsl:value-of select="ParticipantAddress"/>
</td>
<td valign = "top">
<xsl:value-of select="ParticipantListeningPort"/>
</td>
<td valign = "top">
<xsl:value-of select="MMListeningPort"/>
</td>
<td valign = "top">
<xsl:value-of select="SSRCFromParticipant"/>
</td>
<td valign = "top">
<xsl:value-of select="SSRCFromMM"/>
</td>
</tr>
</td>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
</xsl:if>
<xsl:if test="MediaMixer= ''">
<td valign = "top">
<xsl:text>No Data </xsl:text>
</td>
</xsl:if>
</table>
</td>
</tr>
</table>
 
<div style="display:none">
<iframe id="frameUpdate" name="frameUpdate" width="100%"></iframe>
</div>
</div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Let us assume that I wish to change ID1 to upper-case. How do i do it ?
Add at the top, before <xsl:template match="/">:
<xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'" />
<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
And your ID1 selector will be probably:
<td valign = "top">
<xsl:value-of select="translate(ID1, $smallcase, $uppercase)" />
</td>

Using XSLT/XML to generate styles for HTML tags? (xsl:attribute-set)

Okay, it's been a tough hour or so... I'm having difficulties generating table cells with different widths. I'm using XML/XSLT to spit out my HTML, so basically the widths are stored in XML format:
<size>
<width1>5</width1>
<width2>4</width2>
<width3>7</width3>
</size>
Using XSLT's attribute-set I should have a table row and cells with 5px, 4px, 7px widths respectively. However, the trouble with this is that attribute-set needs to be a child of <xsl:stylesheet> for it to work. I CAN'T do this: (forgive the missing px)
<tr>
<td>
<xsl:attribute-set name="style">
<xsl:attribute name="width"><xsl:value-of select="size/width1"/></xsl:attribute>
</xsl:attribute-set>
</td>
<td>
<xsl:attribute-set name="style">
<xsl:attribute name="width"><xsl:value-of select="size/width2"/></xsl:attribute>
</xsl:attribute-set>
</td>
<td>
<xsl:attribute-set name="style">
<xsl:attribute name="width"><xsl:value-of select="size/width3"/></xsl:attribute>
</xsl:attribute-set>
</td>
</tr>
Is there any way to generate html tag using XML data to style them?
Instead of xsl:attribute-set you need to add an xsl:attribute inside your <td> element:
<xsl:template match="size">
<tr>
<td>
<xsl:attribute name="width">
<xsl:value-of select="./width1"/>
</xsl:attribute>
</td>
<td>
<xsl:attribute name="width">
<xsl:value-of select="./width2"/>
</xsl:attribute>
</td>
<td>
<xsl:attribute name="width">
<xsl:value-of select="./width3"/>
</xsl:attribute>
</td>
</tr>
</xsl:template>
More XSLT style:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:template match="size">
<table>
<tr>
<xsl:apply-templates/>
</tr>
</table>
</xsl:template>
<xsl:template match="size/*">
<td style="width:{.}px;">
<!-- Do stuff -->
</td>
</xsl:template>
</xsl:stylesheet>
Applied to your sample result will be:
<table>
<tr>
<td style="width:5px;"></td>
<td style="width:4px;"></td>
<td style="width:7px;"></td>
</tr>
</table>

Resources