输出html控件-动态控件名称

发布于 2024-07-09 09:52:59 字数 863 浏览 6 评论 0原文

我想使用 xslt 输出 html 控件,但我需要能够命名这些控件,以便在表单回发时可以获取它们。

我希望能够将单选按钮命名为 "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>

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">
  <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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

(り薆情海 2024-07-16 09:52:59

使用:
<强>

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

如果您的 xml 文档发生更改,可能需要用更详细的位置步骤替换上面的“*”字符。

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.

懷念過去 2024-07-16 09:52:59
<?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 节点添加一个匹配器,而不仅仅是在根节点上匹配。

<?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>

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

旧伤还要旧人安 2024-07-16 09:52:59

引用变量时需要在变量前面加上 $ 符号:

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

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 />
逆光下的微笑 2024-07-16 09:52:59

您的数据集具有一个很好的属性,它是一棵树,每个节点都可以通过它在树中的路径来识别。 我想说,最好的选择是以反映这一点的方式命名与每个 XML 节点相对应的控件:

  1. NewDataSet_Cases_Case1_case_id1_rb。
  2. NewDataSet_Cases_Case1_case_id2_rb。

您只需要一种方法来获取父节点的名称,例如:

<xsl:variable name="parent1Name"
              select="name(parent::*)" />

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::*)" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文