我有一个这样的XML例子:XSLT发送变量另一个模板
<p class="exer_header" style="display: none;">
<image-input size="5" value="val1" />
</p>
<p class="exer_header" style="display: none;">
<image-input size="5" value="val2" />
</p>
<answers-img>
<answer-img class="imagednd_answer1" value="val1"/>
<answer-img class="imagednd_answer2" value="val2"/>
</answers-img>
和XSLT前。在这里:
<xsl:template match="image-input">
<xsl:variable name="id" select="generate-id(.)"/>
<xsl:element name="input">
<xsl:attribute name="id"><xsl:value-of select="$id"/></xsl:attribute>
<xsl:attribute name="class">exer_input</xsl:attribute>
</xsl:element>
</xsl:template>
<xsl:template match="answers-img">
<xsl:for-each select="//image-input">
<xsl:element name="div">
<xsl:element name="input">
<xsl:attribute name="class">ans_img_input</xsl:attribute>
<xsl:attribute name="type">hidden</xsl:attribute>
<xsl:attribute name="value">***{ID}***</xsl:attribute>
</xsl:element>
<xsl:apply-templates select="//answers-img/answer-img"/>
</xsl:element>
</xsl:for-each>
</xsl:template>
问题是下一步,我如何发送一个变量ID从“输入”模板到另一个“答案-IMG”模板,改变{ID} ?
UPD:在 “回答-IMG” 我需要生成 “输入IMG” 相同ID的。首先xslt使用“input-img”(两次)生成代码,而当其他模板(不在“input-img”中)调用模板“answer-img”时。也许我可以创建全局数组变量?