Hi,
I have a DropDownList which source is an XML Doc. However, the items displayed by the DropDownList are not sorted. My Goal is to be able to sort the items in the DropDownList.
I understand that I can achieve the sorting issue via an XSL doc. Is this correct? If so, my attempts have not been successful so far.
Here's what I got:
A sample of my XML file is:
and here is the xsl I wrote:
Thank you for any help provided!!!
I have a DropDownList which source is an XML Doc. However, the items displayed by the DropDownList are not sorted. My Goal is to be able to sort the items in the DropDownList.
I understand that I can achieve the sorting issue via an XSL doc. Is this correct? If so, my attempts have not been successful so far.
Here's what I got:
Code:
protected void Button1_Click(object sender, EventArgs e)
{
if (selection.SelectedValue == "")
{
AlertMsg("Please select a role.");
goto Exit;
}
this.selection.BackColor = Color.White;
this.lblPath.Visible = true;
this.selection2.Visible = true;
this.selection2.Items.Clear();
this.Button2.Visible = true;
xDoc.Load(xmlPath);
[COLOR=green]//Trying to Transform XML file to sort [/color]
[b][COLOR=red]XslCompiledTransform xslDoc = new XslCompiledTransform();
xslDoc.Load(Server.MapPath("sortAudience.xsl"));
XmlTextWriter writer = new XmlTextWriter(Response.Output);
writer.WriteStartDocument();
xslDoc.Transform(xDoc, null, writer);[/color][/b]
audienceList = xDoc.SelectNodes("/dataroot/Partner_x0020_Readiness_x0020_List[Audience='" + selection.SelectedValue + "']/Path_x0020_Type");
foreach (XmlNode n in audienceList)
{
item = new ListItem(n.InnerText, n.InnerText);
this.selection2.Items.Add(item);
}
this.selection2.Items.Insert(0, "");
Exit: ;
}
A sample of my XML file is:
Code:
<?xml version="1.0" encoding="UTF-8"?>
[b][COLOR=red]<dataroot[/color] [/b]xmlns:od="urn:schemas-microsoft-com:officedata" xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"[/URL] xsi:noNamespaceSchemaLocation="Partner%20Readiness%20List.xsd" generated="2007-05-17T21:52:53">
[b][COLOR=red]<Partner_x0020_Readiness_x0020_List>[/color][/b]
<ID>66</ID>
<Title>5178: Implementing Conferencing Solutions Using Microsoft Office Communications Server 2007 and Live Meeting</Title>
<Product>
<Value>LCS 2005/OCS 2007</Value>
</Product>
<Form_x0020_Factor>
<Value>Instructor Led Training</Value>
</Form_x0020_Factor>
<Content_x0020_Level>300</Content_x0020_Level>
<Availability>2007-10-03T00:00:00</Availability>
<Source>MS Learning</Source>
<Path_x0020_Type>
<Value>UC Specializations</Value>
</Path_x0020_Type>
<Partner_x0020_Type>All</Partner_x0020_Type>
<Core>Yes</Core>
<Exam_x0020_Mapping>70-638</Exam_x0020_Mapping>
[b][COLOR=red]<Audience>[/color][/b]Implementer</Audience>
<Audience_x0020_Level>Experienced</Audience_x0020_Level>
</Partner_x0020_Readiness_x0020_List>
and here is the xsl I wrote:
Code:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
<xsl:template match="/">
<html>
<dataroot>
<xsl:apply-templates/>
</dataroot>
</html>
</xsl:template>
<xsl:template match="Partner_x0020_Readiness_List">
<Partner_x0020_Readiness_List>
[b][COLOR=red]<xsl:for-each select="dataroot/Partner_x0020_Readiness_List">
<xsl:sort select="Audience"/>[/color][/b]
</xsl:for-each>
</Partner_x0020_Readiness_List>
</xsl:template>
</xsl:stylesheet>
Thank you for any help provided!!!