我有如下所示的 XML:
<library>
<album>
<!-- Album title, length, # of tracks, etc -->
<playas>
<extension>.mp3</extension>
<type>audio/mpeg</type>
</playas>
<playas>
<extension>.ogg</extension>
<type>audio/ogg</type>
</playas>
<track>
<!-- Track number, title, length -->
</track>
<!-- Many, many more tracks -->
</album>
</library>
在我的 XLS 文件中,我想用它xls:for-each
来确定每个轨道的source
src 属性。这是不起作用的:
<xsl:for-each select="track">
<audio>
<!-- Parent (album)'s playas elements -->
<xsl:for-each select="../playas">
<source>
<xsl:attribute name="src">
<!-- Parent (album)'s title + '-src', where I store the audio files
along with current node (playas)'s extension -->
<xsl:value-of select="../title" />-src/<xsl:value-of select="title" /><xsl:value-of select="extension" />
</xsl:attribute>
<xsl:attribute name="type">
<xsl:value-of select="srctype" />
</xsl:attribute>
</source>
</xsl:for-each>
</audio>
</xsl:for-each>
上面的代码给出了<source src="AlbumTitle-src/.mp3" type="audio/mpeg"> (or .ogg and audio/ogg)
- 当前track
的标题不存在。但是,为每个曲目正确创建了代码,所以我只需要知道如何获取当前曲目的标题(来自 playas 的上下文)。
我也试过for-each select="preceding-sibling::playas"
了,没有运气。如何在playas
不“离开” current的情况下访问每个孩子的孩子track
?
编辑:我知道这很容易通过简单地<source>
为每个 playas 扩展硬编码 a 来完成,但我想用最少的实现来做到这一点。
编辑 2: @Peter:我对每首曲目的预期输出(在等效的 HTML 中)是
<audio>
<source src="AlbumTitle-src/track.mp3" type="audio/mpeg" />
<source src="AlbumTitle-src/track.ogg" type="audio/ogg" />
</audio>