2011-08-12 2 views
0

iTunes Music Library.xml 파일에서 정보를 추출해야합니다. xml은 plist의 형태이기 때문에 조금 번거로워졌습니다.iTunes에서 정보 추출하기 Music Library XML with XSLT?

나는 누구의 "재생 목록 ID"나는이 특정 재생 목록에서 모든 트랙 ID의 목록을 얻을 싶어요.

예를 들어, iTunes 재생 목록은 다음과 같습니다.

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 
<plist version="1.0"> 
<dict> 
    <key>Playlists</key> 
    <array> 
     <dict> 
      <key>Name</key><string>Library</string> 
      <key>Master</key><true/> 
      <key>Playlist ID</key><integer>4053</integer> <!--Ex:4053 I have.--> 
      <key>Playlist Items</key> 
      <array> 
       <dict> 
        <key>Track ID</key><integer>2413</integer> 
       </dict> 
       <dict> 
        <key>Track ID</key><integer>2083</integer> 
       </dict> 
       <dict> 
        <key>Track ID</key><integer>2081</integer> 
       </dict> 
       <dict> 
        <key>Track ID</key><integer>6798</integer> 
       </dict> 
         </array> 
        <dict> 
        <!-- Here another playlist will start. with diff playlist ID --> 
      <array> 

</dict> 
</plist> 

자세한 내용은 iTunes Music Library.xml을 확인하십시오.

기본적으로 내가 필요한 것은 이것입니다. (a) 재생 목록 ID (여기 4053)가 있으면 해당 재생 목록 아래의 모든 트랙 ID 값 (여기 : 2413,2083,2081,6798)을 인쇄하십시오.

내 시도 :

<?xml version="1.0" encoding="ISO-8859-1"?> 

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

<xsl:output method="text" /> 

<xsl:template match="/"> 


<xsl:for-each select="plist/dict/array/dict"> 

    <xsl:choose> 
     <xsl:when test="child::integer[preceding-sibling::key[1]='Playlist ID']=4053"> 
      <!-- condition is not working fine, Below lines are working fine --> 
     <xsl:for-each select="plist/dict/array/dict/array/dict"> 
      <xsl:value-of select="child::integer[preceding-sibling::key[1]='Track ID']"/> 
      </xsl:for-each> 
     </xsl:when> 
    </xsl:choose> 


</xsl:for-each> 

</xsl:template> 

</xsl:stylesheet> 

는 XSLT에 어떤 전문가들은 여기 좀 도와 수 있습니다. 나는 매우 기뻐할 것입니다.

+1

올바른 입력 XML을 작성하십시오, 유효한 XML이 아닙니다 (닫는 태그가 없습니다). 그리고 샘플 출력을 보여 주면 도움이 될 것입니다. – therealmarv

+0

안녕하세요 "therealmarv", 내 질문을 수정했습니다. 기본적으로 itunes 음악 library.xml 파일을 구문 분석하고 있습니다. iTunes가 설치되어있는 경우 xml 형식을보다 잘 이해하기 위해 xml 라이브러리를 확인할 수 있습니다. 그러나 나는 그것을 위에 설명했다. 감사. –

+0

Mac OS X : (iTunes 라이브러리 파일 경로) **/사용자/사용자 이름/음악/iTunes/iTunes Library.xml ** Windows XP ** \ Documents and Settings \ 사용자 이름 \ My Documents \ My Music \ iTunes \ 아이튠즈 Library.xml에 ** 윈도우 비스타 ** \ 사용자 \ 사용자 이름 \ 음악 \ iTunes를 \ 아이튠즈 Library.xml에 ** 윈도우 7 ** \ 사용자 \ 사용자 이름 \ 내 음악 \ iTunes를 \ 아이튠즈 Library.xml에 ** –

답변

2

어리석은 실수를 저질렀습니다. for-each 루프 내부의 경로는 상대 경로 여야합니다. 나는 누군가를 도울지도 모른다 응답을 배치하고있다.

<?xml version="1.0" encoding="ISO-8859-1"?> 

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

<xsl:output method="text" /> 

<xsl:template match="/"> 


<xsl:for-each select="plist/dict/array/dict"> 

    <xsl:choose> 
     <xsl:when test="child::integer[preceding-sibling::key[1]='Playlist ID']=4053"> 
     <xsl:for-each select="array/dict"> <!--**This should be relative**--> 
      <xsl:value-of select="child::integer[preceding-sibling::key[1]='Track ID']"/> 
      </xsl:for-each> 
     </xsl:when> 
    </xsl:choose> 

</xsl:for-each> 

</xsl:template> 

</xsl:stylesheet> 

감사합니다.