Problem setting variables in XSLT from C#

Can't get xslt variable to work for some reason

Page 1 of 1

1 Replies - 3805 Views - Last Post: 10 September 2010 - 11:03 PM Rate Topic: -----

#1 mulevad  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 21-April 09

Problem setting variables in XSLT from C#

Posted 10 September 2010 - 02:56 PM

I am trying to use a variable in an XSL transform using a C# XML control. (Visual Studio 2010, .NET 4.0 - I think)

Here is the C#
       private void PopulateXML( Xml MyXML)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(Server.MapPath("MyXML.xml"));
            XslTransform trans = new System.Xml.Xsl.XslTransform();
            trans.Load(Server.MapPath("MyXSL.xsl"));
            MyXML.Document = doc;

            //get sort
            string SortKey = DropDownList1.SelectedValue.ToLower();
            XsltArgumentList xslArg = new XsltArgumentList();
            xslArg.AddParam("sortkey", "", SortKey);
            MyXML.TransformArgumentList = xslArg;
            MyXML.Transform = trans;
        }



Here is some of my XSL
  <html>
  <body>
    <xsl:variable name ="sortkey" select ="country"></xsl:variable>
    <h2>Not Actually My CD Collection sorted on $sortkey</h2>


For some reason $sortkey is printing as "$sortkey" and not resolving to a variable.

I step through the code and the XML object has the paramater, but it's not in the output sent to the page.
(I actually am trying to use the variable in an
<xsl:sort select="$sortkey"/>
statement, but I couldn't even get it to work in-line.)

Thanks,
Dave

This post has been edited by mulevad: 11 September 2010 - 10:36 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Problem setting variables in XSLT from C#

#2 mulevad  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 21-April 09

Re: Problem setting variables in XSLT from C#

Posted 10 September 2010 - 11:03 PM

Should I be creating a different version of my XSLT file for each sort and then transforming the XML with the new XSLT?

I was able to get my transform to work using multiple XSLT files and switch-ing on the sortkey that was selected, and using that one for the transform. This is not the ideal method.

Perhaps I should be generating sort specific XSLT files somehow.

Any guidance would be appreciated.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1