2015-11-03 25 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

看起來像它的工作 - 謝謝! –