Html output controls - dynamic control name

I would like to output html controls using xslt, but I need to be able to name the controls so that I can get them when submitting the form.

I would like to name a radio button "action_" + _case_id.

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="data.xsl"?>
<NewDataSet>
  <Cases>
    <Case>
      <case_id>30</case_id>
    </Case>
  <Cases>
</NewDataSet>

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
     <div class="your_action">
      Your action:<br />
      <input type="radio" name="?" value="No" checked ="true"/> nothing to report<br />
      <input type="radio" name="?" value="Yes" /> memo to follow
    </div>
  </xsl:template>
</xsl:stylesheet>
+3
source share
4 answers

Using:


<input type = "radio" name = "{concat ('action_', / * / * / * / case_id)}"
 value = "No" checked = "true" />

If your XML document changes, you may need to replace the "*" characters above with more detailed placement steps.

+3
source
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="data.xsl"?>
<NewDataSet>
  <Cases>
    <Case>
      <case_id>30</case_id>
    </Case>
  <Cases>
</NewDataSet>

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
     <xsl:variable name="actionid">action_<xsl:value-of select="Cases/Case/case_id"/></xsl:variable>
     <div class="your_action">
      Your action:<br />
      <input type="radio" name="{actionid}" value="No" checked ="true"/> nothing to report<br />
      <input type="radio" name="{actionid}" value="Yes" /> memo to follow
    </div>
  </xsl:template>
</xsl:stylesheet>

. . , Case node, node.

0

When referencing it, you need a variable prefix with the $ icon:

<input type="radio" name="{$actionid}" value="No" checked ="true"/> nothing to report<br />
0
source

Your dataset has the nice property that it is a tree, each node can be identified by this path in the tree. I would say that it is best to name the controls corresponding to each XML node, in a way that reflects this:

  • NewDataSet_Cases_Case1_case_id1_rb.
  • NewDataSet_Cases_Case1_case_id2_rb.

You just need a way to get the names of the parent nodes, for example:

&lt;xsl:variable name="parent1Name"
              select="name(parent::*)" /&gt;
0
source

All Articles