XML ドキュメント構造に従う必要があります。
<option_set id="1">
<option>Yes</option>
<option>No</option>
<option>Maybe</option>
</option_set>
<question option_set="1">
<text>Do you like cake?</text>
</question>
<question option_set="1">
<text>Is the cake a lie?</text>
</question>
物事を DRY に保つために、共通のオプション セットを共有するいくつかの異なる質問を用意することが考えられます。これらは、XSLT を使用して構築できます。私のテンプレートは次のとおりです。
<xsl:template match="question[@option_set and not(option)]">
<!-- Build a whole question with its options
(copy the options across and then apply-templates?) -->
</xsl:template>
<xsl:template match="question[option]">
<!-- Match a whole question, with options, for making pretty HTML out of -->
</xsl:template>
一番上のテンプレートが私の質問と一致すると、次のようなものが残るという考えです。
<question>
<text>Do you like cake?</text>
<option>Yes</option>
<option>No</option>
<option>Maybe</option>
</question>
...次に、下部のテンプレートと一致させて、HTML ドキュメントに挿入できます。私の質問は、実際にそれを行う (トップ) テンプレートをどのように作成するかです。私は近くにいますが、これはまだ機能していません:
<xsl:template match="question[@option_set and not(option)]">
<xsl:variable name="optset" select="@option_set"/>
<xsl:copy>
<xsl:copy-of select="text"/>
<xsl:copy-of select="//option_set[@id=$optset]/option"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
変換された質問ブロックとそのオプションは、最上位のテンプレートによって取得されてきれいな HTML に変換されるのではなく、ドキュメントにコピーされます。
しようとすると<xsl:apply-templates select="."/>
、無限ループに陥ります。