我正在做一个项目并且遇到了问题。我最近确定无法更改变量值,并且似乎无法找到解决此问题的方法。我需要创建通用的代码,但我无法做到这一点。
我的 XSLT 代码......
<tracklist>
<xsl:for-each select = "VinylRecord/Tracks/Song">
<xsl:choose>
<xsl:when test = "@Track = 1">
<xsl:element name="side{@Side}">
<xsl:variable name = "d" select = "@Track"/>
<xsl:for-each select = "../Song">
<xsl:choose>
<xsl:when test = "@Side = ../Song/following:: @Side">
<track>
<xsl:attribute name = "no">
<xsl:value-of select = "@Track" />
</xsl:attribute>
<xsl:attribute name = "runtime">
<xsl:value-of select = "Length" />
</xsl:attribute>
<xsl:value-of select = "text()" />
</track>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:element>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</tracklist>
XML 文档…………
<Tracks>
<Song Side="A" Track="1">
The Nerve
<Length>2.58</Length>
</Song>
<Song Side="A" Track="2">
Backfire
<Length>3.22</Length>
</Song>
<Song Side="A" Track="3">
Clipping
<Length>4.05</Length>
</Song>
<Song Side="A" Track="4">
Spotlight
<Length>3.21</Length>
</Song>
<Song Side="A" Track="5">
No Response
<Length>4.01</Length>
</Song>
<Song Side="A" Track="6">
Pins and Needles
<Length>4.05</Length>
</Song>
<Song Side="B" Track="1">
Goodbye
<Length>4.09</Length>
</Song>
<Song Side="B" Track="2">
Odds
<Length>3.01</Length>
</Song>
<Song Side="B" Track="3">
Electrify
<Length>3.49</Length>
</Song>
<Song Side="B" Track="4">
Armistice
<Length>3.54</Length>
</Song>
<Song Side="B" Track="5">
Lost Year
<Length>3.13</Length>
</Song>
<Song Side="B" Track="6">
Burden
<Length>9.06</Length>
</Song>
</Tracks>
...
任何提示将非常感谢
预期结果 ...............
这只是上面显示的整个程序的一个片段,但结果应该显示为:
<tracklist>
<sideA>
<track no="1" runtime="2.58">The Nerve</track>
<track no="2" runtime="3.22">Backfire</track>
<track no="3" runtime="4.05">Clipping</track>
<track no="4" runtime="3.21">Spotlight</track>
<track no="5" runtime="4.01">No Response</track>
<track no="6" runtime="4.05">Pins and Needles</track>
</sideA>
<sideB>
<track no="1" runtime="4.09">Goodbye</track>
<track no="2" runtime="3.01">Odds</track>
<track no="3" runtime="3.49">Electrify</track>
<track no="4" runtime="3.54">Armistice</track>
<track no="5" runtime="3.13">Lost Year</track>
<track no="6" runtime="9.06">Burden</track>
</sideB>
</tracklist>