2016-04-06 55 views
0

我的合併文件看起來像這樣排序使用XSL

<?xml version="1.0" encoding="UTF-8"?> 
<lineup> 
    <artists> 
     <artist id="124"> 
     <name>Pascal &amp; Pearce</name> 
     <genres> 
      <genre>dance</genre> 
      <genre>club</genre> 
     </genres> 
     <writeup> 
     After a chance meeting in 2007, Pascal Ellinas and Dave Pearce began the long winding road that is now the stellar production and DJ duo of Pascal &amp; Pearce. 
    </writeup> 
     <gig> 
      <day>SUNDAY</day> 
      <time> 
       <starts>17:00</starts> 
       <ends>19:00</ends> 
      </time> 
     </gig> 
     <photo format="jpg">pascal-pierce</photo> 
     </artist> 
     <aritst id="101"> 
     <name>Dan Patlansky</name> 
     <genres> 
      <genre>Blues</genre> 
      <genre>Rock</genre> 
      <genre>Jazz</genre> 
     </genres> 
     <writeup> 
     What Dan Patlansky can do with a six-string Fender Stratocaster at the age of 26, most critically acclaimed guitarists will never quite achieve in a lifetime. 
    </writeup> 
     <gig> 
      <day>Friday</day> 
      <time> 
       <starts>13:00</starts> 
       <ends>15:00</ends> 
      </time> 
     </gig> 
     <photo format="jpg">dan-patlansky</photo> 
     </aritst> 
     etc 

我需要藝術家名字的字母順序排序合併XML元素的名字,這是我迄今爲止,但它不會產生任何東西。這是我的XSL文件。

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

    <xsl:output method="xml" omit-xml-declaration="no" indent="yes" media-type="text/xml" /> 

    <xsl:template match="/"> 
     <lineup> 
     <artists> 
      <xsl:apply-templates select="artists/artist"> 
       <xsl:sort select="name" order="ascending" /> 
      </xsl:apply-templates> 
     </artists> 
     </lineup> 
    </xsl:template> 

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

</xsl:stylesheet> 

我的輸出產生一個只有一個標籤的空文件。我的合併文件是我的源文件。 幫助將不勝感激,謝謝。

回答

1

作爲快速修復,請將<xsl:apply-templates select="artists/artist">更改爲<xsl:apply-templates select="lineup/artists/artist">

它會更簡單,以匹配

<xsl:template match="artists"> 
    <xsl:copy> 
    <xsl:apply-templates select="artist"> 
     <xsl:sort select="name"/> 
    </xsl:apply-templates> 
    </xsl:copy> 
</xsl:template> 
+0

太謝謝你了。我只是試圖說明它僅僅顯示了第一個「藝術家」。僅「Pascal & Pearce」細節。 – KhanyisileC

+2

因爲你的第二個藝術家是一個'aritst' – wero

+0

@wero我該如何解決這個問題? – KhanyisileC