0

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:

  1. --Select--
  2. Agriculture
  3. Airline

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:

  1. <xsl:value-of select="aspdnsf:StringResource('industry.cs.1')" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"/>
  2. Air
  3. <xsl:value-of select="$pReplacement" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"/>

I would sure appreciate it if someone could tell me what I am doing wrong here.

Thanks in advance!

1
  • Probably you are trying too much in one step. Separate the usage of the XML file for a drop down box from generating the XML via XSLT. In which area is the problem? Commented Aug 28, 2021 at 9:35

1 Answer 1

0

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!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.