我对 XSLT 完全陌生,正在尝试转换以下 XML:
<array>
<!-- red herring -->
<Telop ID="t01">
<time>0</time>
<Sentence />
</Telop>
<!-- start time and label -->
<Telop ID="t02">
<time>14</time>
<Sentence>Subtitle 1</Sentence>
</Telop>
<!-- end time -->
<Telop ID="t03">
<time>26</time>
<Sentence />
</Telop>
<!-- start time and label -->
<Telop ID="t04">
<time>44</time>
<Sentence>Subtitle 2</Sentence>
</Telop>
<!-- end time -->
<Telop ID="t05">
<time>48</time>
<Sentence />
</Telop>
</array>
进入以下结构,其中备用节点提供开始时间和标签,紧随其后的兄弟节点提供结束时间:
<div>
<p begin="00:00:14.000" end="00:00:26.000">Subtitle 1</p>
<p begin="00:00:44.000" end="00:00:48.000">Subtitle 2</p>
</div>
我拼凑了以下内容:
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<div xml:lang="en" style="1">
<xsl:for-each select="array/Telop">
<xsl:if test="not(position() mod 2)">
<p>
<xsl:attribute name="begin">
<xsl:value-of select="time" />
</xsl:attribute>
<xsl:attribute name="end">
<!-- How can I get the time from the immediate following sibling? -->
<xsl:value-of select="/following-sibling::time" />
</xsl:attribute>
<xsl:value-of select="Sentence" />
</p>
</xsl:if>
</xsl:for-each>
</div>
</xsl:template>
这非常接近,但我不知道如何提取紧随其后的兄弟的时间值。