Reputation: 1
I created an XML file and can successfully use that information to create a drop down list. What I would like to achieve is to add variables from a stringResource file to create the values for the drop down list.
my original XML file is:
<root>
<row>
<var name="--Select--"/>
</row>
<row>
<var name="Agriculture"/>
</row>
<row>
<var name="Airline"/>
</row>
<root>
in trying to add variables I have tried the following:
<PackageTransform>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:aspdnsf="urn:aspdnsf" exclude-result-prefixes="aspdnsf">
<xsl:output method="html" omit-xml-declaration="yes" />
<xsl:template match="row">
<xsl:param name="pReplacement" select="'Something Different'"/>
<root>
<row>
<xsl:value-of select="aspdnsf:StringResource('industry.cs.1')"/>
</row>
<row>
Air
</row>
<row>
<xsl:value-of select="$pReplacement" />
</row>
</root>
</xsl:template>
</xsl:stylesheet>
my working code, with the original XML file is:
XmlNodeList industrylist = XmlDoc.GetElementsByTagName("row");
foreach (XmlNode Node in industrylist)
{
string industry = Node["var"].Attributes["name"].Value;
_cboIndustryType.Items.Add(new ListItem(industry));
}
With the top XML file my drop down list correctly lists all the names:
I could not set the attribute name as a variable so I changed the code to look for the node innerXML like so:
XmlNodeList industrylist = XmlDoc.GetElementsByTagName("row");
foreach (XmlNode Node in industrylist)
{
string industry = Node.InnerXml;
_cboIndustryType.Items.Add(new ListItem(industry));
}
but after many attempts such as the second XML file I am not able to get the variable to display correctly. I am seeing the following list:
I would sure appreciate it if someone could tell me what I am doing wrong here.
Thanks in advance!
Upvotes: 0
Views: 451
Reputation: 1
I figured out a way to do what I want.
I just wrote 2 different XML files, one in each language then changed the code to pick the appropriate one based on locale.
if (Customer.Current.LocaleSetting.Contains("es"))
XmlDoc.Load(CommonLogic.SafeMapPath("~/XmlPackages") + "\\industry.drop.down.list.es-MX.xml.config");
else
XmlDoc.Load(CommonLogic.SafeMapPath("~/XmlPackages") + "\\industry.drop.down.list.xml.config");
XmlNodeList industrylist = XmlDoc.GetElementsByTagName("row");
foreach (XmlNode Node in industrylist)
{
string industry = Node.InnerXml;
_cboIndustryType.Items.Add(new ListItem(industry));
}
Thanks!
Upvotes: 0