2015-11-03 23 views
0

任何人都有想过如何对此进行排序?我想按照xlst中的升序时间码值进行排序,但我不认为典型的排序会正确读取时间码值。在XLST中排序时间代码

我的最终目标是:1)显示结果时间码值上升2节点),选择相应的颜色,然后第二个,第一次迭代的时间码值,那么第三等

请让我知道我是否需要澄清更多。

这里的XML:

<Metadata> 
    <Locator> 
    <Label>OUT</Label> 
    <Color>Blue</Color> 
    <Timecode>00;13;28;26</Timecode> 
    <Username>bpayne</Username> 
    <Track>V1</Track> 
</Locator> 
    <Locator> 
    <Label>OUT</Label> 
    <Color>Magenta</Color> 
    <Timecode>00;15;29;26</Timecode> 
    <Username>bpayne</Username> 
    <Track>V1</Track> 
    </Locator> 
<Locator> 
    <Label>IN</Label> 
    <Color>Magenta</Color> 
    <Timecode>00;23;48;19</Timecode> 
    <Username>bpayne</Username> 
    <Track>V1</Track> 
</Locator> 
<Locator> 
    <Label>IN</Label> 
    <Color>Magenta</Color> 
    <Timecode>00;03;15;13</Timecode> 
    <Username>bpayne</Username> 
    <Track>V1</Track> 
</Locator> 
<Locator> 
    <Label>OUT</Label> 
    <Color>Magenta</Color> 
    <Timecode>00;19;50;25</Timecode> 
    <Username>bpayne</Username> 
    <Track>V1</Track> 
</Locator> 
<Locator> 
    <Label>IN</Label> 
    <Color>Magenta</Color> 
    <Timecode>00;25;58;05</Timecode> 
    <Username>bpayne</Username> 
    <Track>V1</Track> 
</Locator> 
<Locator> 
    <Label>IN</Label> 
    <Color>Magenta</Color> 
    <Timecode>00;07;44;29</Timecode> 
    <Username>bpayne</Username> 
    <Track>V1</Track> 
</Locator> 
<Locator> 
    <Label>OUT</Label> 
    <Color>Magenta</Color> 
    <Timecode>00;09;05;28</Timecode> 
    <Username>bpayne</Username> 
    <Track>V1</Track> 
</Locator> 
<Locator> 
    <Label>IN</Label> 
    <Color>Blue</Color> 
    <Timecode>00;02;19;23</Timecode> 
    <Username>bpayne</Username> 
    <Track>V1</Track> 
</Locator> 
<Locator> 
<Label>OUT</Label> 
    <Color>Magenta</Color> 
    <Timecode>00;13;16;11</Timecode> 
    <Username>bpayne</Username> 
    <Track>V1</Track> 
</Locator> 
<Locator> 
    <Label>OUT</Label> 
    <Color>Blue</Color> 
    <Timecode>00;02;31;23</Timecode> 
    <Username>bpayne</Username> 
    <Track>V1</Track> 
</Locator> 

而且这里是我使用的XLST的一部分。我需要先通过时间码值的节点进行排序,然后用这个XSLT转换它:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    exclude-result-prefixes="xs" 
    version="2.0"> 
    <xsl:template match="/"> 
     <TimeCodes> 
      <G1_TC_1_IN> 
       <xsl:choose> 
        <xsl:when test="Metadata/Locator[Color = 'Magenta'][1]"> 
         <xsl:value-of select="concat(
         substring-before(Metadata/Locator[Color = 'Magenta'][1]/Timecode, ';'), ':', 
         substring-before(substring-after(Metadata/Locator[Color = 'Magenta'][1]/Timecode, ';'), ';'), ':', 
         substring-after(substring-after(Metadata/Locator[Color = 'Magenta'][1]/Timecode, ';'), ';') 
         )"/> 
        </xsl:when>  
        <xsl:otherwise>18:00:00;00</xsl:otherwise> 
       </xsl:choose> 
       <xsl:text>@29.97</xsl:text> 
      </G1_TC_1_IN> 
      <G1_TC_1_OUT> 
       <xsl:choose> 
        <xsl:when test="Metadata/Locator[Color = 'Magenta'][2]"> 
         <xsl:value-of select="concat(
          substring-before(Metadata/Locator[Color = 'Magenta'][2]/Timecode, ';'), ':', 
          substring-before(substring-after(Metadata/Locator[Color = 'Magenta'][2]/Timecode, ';'), ';'), ':', 
          substring-after(substring-after(Metadata/Locator[Color = 'Magenta'][2]/Timecode, ';'), ';') 
          )"/> 
        </xsl:when>  
        <xsl:otherwise>18:00:00;00</xsl:otherwise> 
       </xsl:choose> 
       <xsl:text>@29.97</xsl:text> 
      </G1_TC_1_OUT> 
........ 

<G2_TC_1_IN> 
       <xsl:choose> 
        <xsl:when test="Metadata/Locator[Color = 'Blue'][1]"> 
         <xsl:value-of select="concat(
          substring-before(Metadata/Locator[Color = 'Blue'][1]/Timecode, ';'), ':', 
          substring-before(substring-after(Metadata/Locator[Color = 'Blue'][1]/Timecode, ';'), ';'), ':', 
          substring-after(substring-after(Metadata/Locator[Color = 'Blue'][1]/Timecode, ';'), ';') 
          )"/> 
        </xsl:when>  
        <xsl:otherwise>18:00:00;00</xsl:otherwise> 
       </xsl:choose> 
       <xsl:text>@29.97</xsl:text> 
      </G2_TC_1_IN> 
+1

你谈论排序,但我没有在你的代码中看到任何'xsl:sort'。你能发布你想要为你发布的XML输入创建的结果吗? –

回答

0

排序,您可以使用apply-templates与嵌套sort,例如

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> 

    <xsl:strip-space elements="*"/> 
    <xsl:output indent="yes"/> 

    <xsl:template match="@*|node()"> 
     <xsl:copy> 
      <xsl:apply-templates select="@*|node()"/> 
     </xsl:copy> 
    </xsl:template> 

    <xsl:template match="Metadata"> 
     <xsl:copy> 
      <xsl:apply-templates select="Locator"> 
       <xsl:sort select="Timecode"/> 
      </xsl:apply-templates> 
     </xsl:copy> 
    </xsl:template> 
</xsl:transform> 

在线在http://xsltransform.net/bFN1y8X。只要用逗号分隔的所有数值都有两位数,就像你的数值一样(00;02;31;23)。

+0

看起来像它的工作 - 谢谢! –