2013-07-04 6 views
1

에 (현재 노드를 떠나지 않고) I는 다음과 같습니다 XML을 . 다음은 작동하지 않습니다 무엇 :선택 자식 요소 XLST

<xsl:for-each select="track"> 
    <audio> 
     <!-- Parent (album)'s playas elements --> 
     <xsl:for-each select="../playas"> 
      <source> 
       <xsl:attribute name="src"> 
        <!-- Parent (album)'s title + '-src', where I store the audio files 
         along with current node (playas)'s extension --> 
        <xsl:value-of select="../title" />-src/<xsl:value-of select="title" /><xsl:value-of select="extension" /> 
       </xsl:attribute> 
       <xsl:attribute name="type"> 
        <xsl:value-of select="srctype" /> 
       </xsl:attribute> 
      </source> 
     </xsl:for-each> 
    </audio> 
</xsl:for-each> 

위의 코드는 <source src="AlbumTitle-src/.mp3" type="audio/mpeg"> (or .ogg and audio/ogg) 제공 - 현재 track의 제목이 존재하지 않습니다. 그러나 코드는 각 트랙마다 올바르게 만들어 지므로 현재 트랙의 제목을 얻는 방법을 알아야합니다 (playas의 컨텍스트에서).

행운을 내기 위해 for-each select="preceding-sibling::playas"도 시도했습니다. 현재 track을 "떠나지 않고"각 playas의 하위 항목에 액세스하려면 어떻게해야합니까?

편집 : 각 playas 확장에 대해 <source>을 단순히 하드 코딩하여 매우 쉽게 수행 할 수 있지만 최소 구현으로 수행하려고합니다.

편집 2 : @ 피터 : 당신은 이미 playas 요소 컨텍스트에 <xsl:for-each select="../playas">의 내부에있는 경우 (해당 HTML에서) 각 트랙에 대한 내 예상 출력은

<audio> 
    <source src="AlbumTitle-src/track.mp3" type="audio/mpeg" /> 
    <source src="AlbumTitle-src/track.ogg" type="audio/ogg" /> 
</audio> 
+0

하는 하위 요소에 의해 당신이 생각됩니다 각각의 트랙을 각 playas와 상관 시키는가? 각 트랙에는 항상 해당 앨범의 모든 playas 형식이 있습니까? –

+0

예, 각 트랙을 각 playas 확장자와 함께 사용할 수 있도록했습니다. 첫 질문에 무엇이 필요한지 잘 모르겠지만 각 playas 내에서 "현재"트랙의 제목에 액세스해야합니다. – Trojan

+0

@trojansdestroy : 예상 출력을 보여 주실 수 있습니까? 당신은 하나의 속성을 만들 수 없습니다 및 처리 두 요소, 나는 당신이 하나의 속성으로 여러 값을 쓸 수 없다는 뜻. 감사합니다 yolu, Peter – Peter

답변

1

입니다. 그러므로 title 자녀를 검색하려면 <xsl:value-of select="title" /> 만 있으면됩니다. 그리고 당신은 내부를위한 각 track의 변수를 설정하고 같은 소스 출력 소자에서 사용 coud 트랙 제목을 검색 할 수 있습니다 :

<xsl:for-each select="track"> 
<audio> 
    <xsl:variable name="track_title" select="title" /> 
    <!-- Parent (album)'s playas elements --> 
    <xsl:for-each select="../playas"> 
     <source> 
      <xsl:attribute name="src"> 
       <!-- Parent (album)'s title + '-src', where I store the audio files 
        along with current node (playas)'s extension --> 
       <xsl:value-of select="title" />-src/<xsl:value-of select="$track_title" /><xsl:value-of select="extension" /> 
      </xsl:attribute> 
      <xsl:attribute name="type"> 
       <xsl:value-of select="srctype" /> 
      </xsl:attribute> 
     </source> 
    </xsl:for-each> 
</audio> 

+0

playas 요소에는 제목 요소가 없습니다 (트랙 제목 만 필요함). 변수를 사용하면 작업이되므로, 감사합니다! 변수가 옵션인지는 몰랐습니다. 그렇지 않으면 그것을 할 수있는 방법이 있습니까? 변수는 일종의 "해킹"처럼 보이고 트랙 제목에 직접 접근 할 수 있어야합니다. – Trojan