Hi,
I've got a problem with showing the correct result from XML-file in my C# program.
I need to show for the chosen record the corresponding data from the XML-file in a webbrowser control. So I need to filter the XML-file, but I don't know how to do that.
Here is an easy example of what I need to do:
XML-file TeamPlayer.xml:
="1.0"
<TeamResult xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Players>
<Player>
<Number>1</Number>
<Name>Player 1</Name>
<FieldPosition>Goalkeeper</FieldPosition>
</Player>
<Player>
<Number>2</Number>
<Name>Player 2</Name>
<FieldPosition>Defender</FieldPosition>
</Player>
<Player>
<Number>5</Number>
<Name>Player 3</Name>
<FieldPosition>Defender</FieldPosition>
</Player>
<Player>
<Number>7</Number>
<Name>Player 4</Name>
<FieldPosition>Midfielder</FieldPosition>
</Player>
<Player>
<Number>13</Number>
<Name>Player 5</Name>
<FieldPosition>Forward</FieldPosition>
</Player>
</Players>
</TeamResult>
I'm using a stylesheet on the XML-file.
XSL-file TeamPlayer.xsl:
="1.0"="utf-8"
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="TeamResult">
<html>
<body>
<center>
<h2>
Team
</h2>
</center>
<hr/>
<hr/>
Players
<br/>
<table border="0">
<xsl:for-each select="Players/Player">
<xsl:value-of select="Number"/> -
<xsl:value-of select="Name"/> -
<xsl:value-of select="FieldPosition"/>
<br/>
</xsl:for-each>
</table>
<hr/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
In my window I've got a grid with all the players.
When I chose a certain player in the grid, I need to see his data from the XML-file in de webbrowser control.
The following code is running after I chose a row in the grid. This code add
="text/xsl"="TeamPlayer.xsl"
to the XML-file
C# TransformXmlToXsl:
private void TransformXmlToXsl(int number) // number = player number
{
string path=@"c:\TeamPlayer\";
string pathLocal=@"c:\TeamPlayer\Temp\";
string xmlFile="TeamPlayer.xml";
string xslFile="TeamPlayer.xsl";
if (!string.IsNullOrEmpty(xmlFile))
{
if (!Directory.Exists(pathLocal))
{
Directory.CreateDirectory(pathLocal);
}
File.Copy(path + xslFile, pathLocal + xslFile, true);
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(xmlFile);
XmlProcessingInstruction newPI;
string xslStyleSheet = string.Format("type=\"text/xsl\" href=\"{0}\"", xslFile);
newPI = xmlDoc.CreateProcessingInstruction("xml-stylesheet", xslStyleSheet);
xmlDoc.InsertBefore(newPI, xmlDoc.DocumentElement);
xmlDoc.Save(pathLocal + xmlFile);
wbXML.Navigate(pathLocal + xmlFile);
}
else
{
wbXML.DocumentText = null;
}
}
The result of the XML-file in the webbrowser control is:
Team
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Players
1 - Player 1 - Goalkeeper
2 - Player 2 - Defender
5 - Player 3 - Defender
7 - Player 4 - Midfielder
13 - Player 5 - Forward
If I chose 'Player 3' the result of the XML-file in the webbrowser control should be filtered and giving the following result:
Team
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Players
5 - Player 3 - Defender
How can I give a parameter to the XML- or XSL-file?
Is this possible?