title: XSLT - Populate XML Form Inputs with Name Value Pair Dictionary
body: <p>I have an xml template for a form which gets rendered using xslt as follows:</p>
  
  <p>xml:</p>
  
  <pre><code>&lt;form-template&gt;
    &lt;fields&gt;
      &lt;field type="text" required="true" label="Subject" class="form-control" name="subject" subtype="text"&gt;&lt;/field&gt;
      &lt;field type="textarea" required="true" label="Description" class="form-control" name="description" subtype="textarea" rows="3"&gt;&lt;/field&gt;
    &lt;/fields&gt;
  &lt;/form-template&gt;
  </code></pre>
  
  <p>xsl:</p>
  
  <pre><code>&lt;xsl:template match="/*"&gt;
       &lt;xsl:for-each select="fields/field"&gt;  
           &lt;xsl:if test="@type='text'"&gt; 
              &lt;label for="{@name}"&gt;&lt;xsl:value-of select="@label"/&gt;&lt;/label&gt;
              &lt;input class="form-control" data-val="{@required}" data-val-required="The {@label} field is required." id="{@name}" name="{@name}" type="text" value=""&gt;&lt;/input&gt;
              &lt;span class="field-validation-valid" data-valmsg-for="{@name}" data-valmsg-replace="true"&gt;&lt;/span&gt;
            &lt;/xsl:if&gt; 
       &lt;/xsl:for-each&gt;  
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p>The form is rendered using a custom HTMLHelper.</p>
  
  <pre><code> @Html.RenderXml(Model.Template, Server.MapPath("~/Content/form.xslt"))
  </code></pre>
  
  <p>The values are stored as name/value pairs:</p>
  
  <pre><code>var values = new Dictionary&lt;string, string&gt; {{"subject", "This is the subject"}, {"description", "This is the description"}};
  </code></pre>
  
  <p>How can I pass these values to the xsl and iterate against each form field in the xml template, if the name matches the  field name then populate the respective field with the value.</p>
  
  <p>I've searched around but I cant see how you can pass an array type variable to an xsl file.</p>
  
  <p>Do I convert the dictionary into a node set and pass it as argumentlist parameter?</p>
  
  <p>Does anyone have any other suggestions or workarounds. some code snippet would be helpful too as I'm not great working with xsl/xml</p>
  
  <p>Note I'm trying to achieve this in .Net MVC</p>