tags:

views:

533

answers:

7

I'd like to output html controls using xslt, but I need to be able to name the controls so that I can get at them when the form posts back.

I'd like to be able to name the 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"&gt;
  <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>
A: 

I can't, there could be thousands of different cases.

Dave
A: 
<?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"&gt;
  <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>

NOTE: Not tested. You probably want add a matcher specifically for the Case node not just matching on the root node.

Artur...
A: 

It's assigning a blank name.

I've tried the following:

<xsl:variable name="lit-actionid">
      lit-action_
    </xsl:variable>

And it still won't grab the variable "lit__action__"

Dave
A: 

You need to prefix the variable with a $ sign when referencing it:

<input type="radio" name="{$actionid}" value="No" checked ="true"/> nothing to report<br />
Johan L
+2  A: 

Use:

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

In case your xml document changes it may be necessary to substitute the "*" chars above with more detailed location steps.

Dimitre Novatchev
A: 

Thanks Dimitre! That worked a treat!!

Dave
A: 

Your dataset has the nice property that it's a tree, each node can be identified by it's path in the tree. I'd say your best bet is to name the controls that correspond to each XML node in a manner that reflects this:
1. NewDataSet_Cases_Case1_case_id1_rb.
2. NewDataSet_Cases_Case1_case_id2_rb.

You just need a way to get the names of the parent nodes, something like:
<xsl:variable name="parent1Name" select="name(parent::*)" />

kokos