XML:
<rating>
<input type="radio" class="cmtRating" name="463[rating]" value="1" />
<input type="radio" class="cmtRating" name="463[rating]" value="2" />
<input type="radio" class="cmtRating" name="463[rating]" value="3" />
<input type="radio" class="cmtRating" name="463[rating]" value="4" />
<input type="radio" class="cmtRating" name="463[rating]" value="5" />
</rating>
如何将ID添加到单选按钮? 这不起作用:
<xsl:copy-of select=".">
<xsl:attribute name="id">rating-input-1-<xsl:value-of select="./@value"/></xsl:attribute>
</xsl:copy-of>
提前谢谢!
答案 0 :(得分:0)
尝试:
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:attribute name="id">rating-input-1-<xsl:value-of select="./@value"/></xsl:attribute>
</xsl:copy>
-
附:尝试发布更多代码。 XSLT非常依赖于上下文,当您不确定当前上下文时,很难提供答案。我甚至不确定这是最好的答案;我怀疑这样做可能更好:
<xsl:template match="input[@type='radio']">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<xsl:attribute name="id">rating-input-1-<xsl:value-of select="./@value"/></xsl:attribute>
</xsl:copy>
</xsl:template>
但我不知道你是否拥有其他模板来处理现有属性。