次のようなxmlがあります。
<field index="1" name="my_field_1" type="String">
<value>Value of Field 1</value>
</field>
<field index="2" name="my_field_2" type="String">
<value>Value of Field 2</value>
</field>
<field index="3" name="my_field_3" type="String">
<value>Value of Field 3</value>
</field>
後で各フィールドを繰り返し処理し、フィールドの名前(同じ)を取得して、インデックス属性(異なる要素の数によって異なります)と連結しようとします。
これを試しました(エスケープする方法がわからなかったので、変数にアポストロフィを入れました)。
<xsl:variable name="currentIndex" select="@index"></xsl:variable>
<xsl:variable name="apostrof">'</xsl:variable>
<xsl:value-of select="concat(
'//field[@name=',
$apostrof,
'sar_account_entrepreneur_name_',
@index,
$apostrof,
']/value')"/>
問題は、これが値を選択する代わりに、文字通り文字列 my_field_1 だけを出力することです。出力は、フィールド 1 の値、フィールド 2 の値などである必要があります。代わりに必要なのは、name 属性と index 属性を動的に連結することです。