我希望对由 for-each 生成的表进行排序。确定排序的数据不包含在 for-each 节点集中,而是包含在 . 节点集和节点集之间有一个common_id。我尝试将 common_id 分配给 for-each 中的局部变量,但排序看不到它。有没有办法做到这一点?下面的一些例子。
示例 XML
<root>
<seq>
<common_id>B1U3</common_id>
<seq_data>1</seq_data>
</seq>
<seq>
<common_id>R3D</common_id>
<seq_data>3</seq_data>
</seq>
<seq>
<common_id>Y3110W</common_id>
<seq_data>2</seq_data>
</seq>
<detail>
<common_id>Y3110W</common_id>
<other_data>spame</other_data>
</detail>
<detail>
<common_id>B1U3</common_id>
<other_data>spamo</other_data>
</detail>
<detail>
<common_id>R3D</common_id>
<other_data>spama</other_data>
</detail>
</root>
所需输出
____________________________
¦Common Id ¦Other Data¦
¦---------------¦----------¦
¦B1U3 ¦spama ¦
¦Y3110W ¦spame ¦
¦R3d ¦spamo ¦
¦_______________¦__________¦
当前的 XSLT
<xsl:template match="/">
<table>
<tr>
<td>Common ID</td>
<td>Other Data</td>
</tr>
<xsl:for-each select="detail">
<xsl:variable name="local_id" select="common_id"/>
<xsl:sort select="../seq[common_id = $local_id]/seq_data"/>
<tr>
<td><xsl:value-of select="common_id"/></td>
<td><xsl:value-of select="other_data"/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>