2017-05-10 51 views
0

我返回的XML具有的圖像,都在不同尺寸的多個值。我試圖在我的XSL中加載圖像,但它總是選擇以XML格式返回的最小(第一個)圖像,所以它非常像素化。訪問XML節點值多張圖片

如何根據屏幕的大小讓瀏覽器選擇正確的瀏覽器?因爲第一個也可能是一個.ico它是這樣的小桌面是非常像素化。

下面是XML數據和XSL文件中的代碼。

XSL:

<xsl:for-each select="lfm/tracks/track"> 
     <xsl:sort order="descending" data-type="number" select="playcount"/> 
      <xsl:if test="position() &lt;= 8"> 
       <xsl:value-of select="result"/> 

         <div class="col s3 m3"> 
          <div class="card large"> 
           <div class="card-image"> 
            <img> 
            <xsl:attribute name="src"> 
             <xsl:value-of select="image"/> 
            </xsl:attribute> 
            </img> 

            <span class="card-title"><xsl:value-of select="name"/></span> 
           </div> 
           <div class="card-content"> 
            <p><xsl:value-of select="name"/> 
            </p> 

            <p><xsl:value-of select="artist/name"/> 
            </p> 

            <p> Playcount: 
             <xsl:value-of select="playcount"/> 
            </p> 
           </div> 

           <div class="card-action"> 
            <a href="view_song.html"><p>Link: 
             <xsl:value-of select="url"/> 
            </p></a> 
           </div> 
          </div> 
         </div> 


      </xsl:if> 
     </xsl:for-each> 

XML:

<track> 
     <name>HUMBLE.</name> 
     <duration>0</duration> 
     <playcount>1063735</playcount> 
     <listeners>136852</listeners> 
     <mbid></mbid> 
     <url>https://www.last.fm/music/Kendrick+Lamar/_/HUMBLE.</url> 
     <streamable fulltrack="0">0</streamable> 
     <artist> 
      <name>Kendrick Lamar</name> 
      <mbid>381086ea-f511-4aba-bdf9-71c753dc5077</mbid> 
      <url>https://www.last.fm/music/Kendrick+Lamar</url> 
     </artist> 
     <image size="small">https://lastfm-img2.akamaized.net/i/u/34s/a4a35fcdf62b8a532039012653eeea14.png</image> 
     <image size="medium">https://lastfm-img2.akamaized.net/i/u/64s/a4a35fcdf62b8a532039012653eeea14.png</image> 
     <image size="large">https://lastfm-img2.akamaized.net/i/u/174s/a4a35fcdf62b8a532039012653eeea14.png</image> 
     <image size="extralarge">https://lastfm-img2.akamaized.net/i/u/300x300/a4a35fcdf62b8a532039012653eeea14.png</image> 
</track> 
+1

你是如何使用這個xsl代碼片段的?它如何運行? – NMGod

+0

我發現我可以訪問不同的圖像,如果我像這樣的圖像下標[4]。 – haydg8

+0

提供更好格式的答案。 – NMGod

回答

0
<xsl:value-of select="image"/> 

image中的XPath將訪問所述第一圖像元件。

如果您要訪問的其他人,你可以使用一個元素的索引像image[3]或更好的,你可以基於它的大小屬性,像下面。

<xsl:value-of select="image[@size = 'large']"/> 
0

通過下標與多個圖像節點解決: <xsl:value-of select="image[2]"/>