我希望使用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>
发布于 2008-12-03 06:12:49
<?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节点添加匹配器,而不仅仅是在根节点上进行匹配。
发布于 2008-12-03 07:05:16
在引用变量时,需要在变量前加上$符号:
<input type="radio" name="{$actionid}" value="No" checked ="true"/> nothing to report<br />
发布于 2008-12-03 07:57:40
你的数据集有一个很好的属性,那就是它是一棵树,每个节点都可以通过它在树中的路径来识别。我想说,最好的方法是以一种反映这一点的方式命名与每个XML节点对应的控件:
您只需要一种方法来获取父节点的名称,如下所示:
<xsl:variable name="parent1Name"
select="name(parent::*)" />
https://stackoverflow.com/questions/337183
复制相似问题