2017-06-28 64 views
0

我想抓取具有多個屬性的節點的airings/mediafile/startTime值。XSL解析一個節點的多個屬性值

這裏是XML的一個片段:

<show epgId="DT523214136"> 
    <title>America Reframed</title> 
    <description>9-Man Teams for this a competitive Chinese-American sport prepare for the national championship in Boston.</description> 
    <airing channelId="129" duration="7200" sageDbId="6422008" startTime="2017-01-25T01:00:00.00Z"> 
     <manualRecord/> 
     <recordSchedule duration="7200" startTime="2017-01-25T01:00:00.00Z"/> 
     <mediafile duration="7200" sageDbId="6423032" startTime="2017-01-25T01:00:00.02Z" type="TV"> 
      <segmentList> 
       <segment duration="7200" filePath="E:\Record\AmericaReframed-6422008-0.mpg" startTime="2017-01-25T01:00:00.02Z"/> 
      </segmentList> 
     </mediafile> 
    </airing> 
</show> 

這裏就是我有。 startTime沒有輸出。我已經嘗試了一切,但xsl令我感到困惑和神祕。

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:user="urn:my-scripts"> 

<xsl:template match="/"> 
<html> 
<body> 
<h2></h2> 
    <table WIDTH="100%" border="1" style="font-family:arial; font-size: 13px;" > 
    <tr bgcolor="#9acd32"> 
     <th style="text-align:left">Title</th> 
     <th style="text-align:left">Description</th> 
      <th style="text-align:left">Category</th> 
     <th style="text-align:left">Date</th> 
    </tr> 
    <xsl:for-each select="sageShowInfo/showList/show"> 
    <xsl:sort select="category"/> 
    <xsl:sort select="title"/> 
    <tr> 
     <td width="30%"><xsl:attribute name="STYLE">color:A50F4B</xsl:attribute><xsl:value-of select="title"/>: <xsl:value-of select="episode"/></td> 
     <td><xsl:value-of select="description"/></td> 
     <td><xsl:value-of select="category"/> </td> 

<xsl:comment>this doesn't work: </xsl:comment> 
     <xsl:for-each select="airing"> 
       <td width="10%"><xsl:value-of select="substring(mediafile/startTime,1,10)"/></td> 
    </xsl:for-each> 
<xsl:comment>-------</xsl:comment> 

    </tr> 
    </xsl:for-each> 
    </table> 

</body> 
</html> 
</xsl:template> 
</xsl:stylesheet> 

回答

0

屬性引用的前綴爲@,所以它應該是

...mediafile/@startTime... 
0

這種說法是試圖選擇媒體文件元素

<xsl:value-of select="substring(mediafile/startTime,1,10)"/> 

內部的開始時間元素的內部文本相反,您應該選擇mediafile元素的startTime屬性:

<mediafile duration="7200" sageDbId="6423032" startTime="2017-01-25T01:00:00.02Z" ... 

所以,你可以使用:

<xsl:value-of select="substring(mediafile/@startTime,1,10)"/> 
+0

優秀。這樣可行。我花費在試圖弄清楚。 – user22998