2013-01-19 5 views
0

for-each 문을 두 개 반복하고 있으며 테이블 내에서 가로 형식이 아닌 세로 형식으로 출력하고 싶습니다.XSL for each eacheration

현재는 출력 :

a b c 
1 2 3 

내가 출력을 원하는 :

a 1 
b 2 
c 3 

수있는 사람의 도움을주십시오?

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:output method="html" indent="no"/> 
    <xsl:key name="names" match="Niche" use="."/> 
    <xsl:key name="niche" match="row" use="Niche"/> 

     <xsl:template match="/"> 
      <table border="1"> 

       <xsl:for-each select="//Niche[generate-id() = generate-id(key('names',.)[1])]"> 
       <xsl:sort select="."/> 

        <td> 
        <xsl:value-of select="."/> 
        </td> 
       </xsl:for-each> 

       <td><tr></tr></td> 

       <xsl:for-each select="//row[generate-id(.)=generate-id(key('niche', Niche)[1])]"> 
       <xsl:sort select="Niche"/> 

        <td> 
        <xsl:value-of select="count(key('niche', Niche))"/> 
        </td> 
       </xsl:for-each> 

      </table> 

    </xsl:template> 
</xsl:stylesheet> 

샘플 XML :

<?xml version="1.0" encoding="ISO-8859-1"?> 
<?xml-stylesheet type="text/xsl" href="sample.xsl" ?> 
<root> 
    <row> 
     <Niche>a</Niche> 
    </row> 
    <row> 
     <Niche>b</Niche> 
    </row> 
    <row> 
     <Niche>b</Niche> 
    </row> 
    <row> 
     <Niche>c</Niche> 
    </row> 
    <row> 
     <Niche>c</Niche> 
    </row> 
    <row> 
     <Niche>c</Niche> 
    </row> 
</root> 
+3

시작하는 XML의 예를 보여줄 수 있습니까? 스타일 시트의 내용을 보지 않고 디코딩하는 것은 어렵습니다. –

답변

2

나는 당신이해야 할 모든이 꽤 확신 :

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output method="html" indent="no"/> 
    <xsl:key name="niche" match="Niche" use="."/> 

    <xsl:template match="/"> 
    <table border="1"> 

     <xsl:for-each select="//Niche[generate-id(.)=generate-id(key('niche', .)[1])]"> 
     <xsl:sort select="."/> 
     <tr> 
      <td> 
      <xsl:value-of select="."/> 
      </td> 
      <td> 
      <xsl:value-of select="count(key('niche', .))"/> 
      </td> 
     </tr> 
     </xsl:for-each> 

    </table> 

    </xsl:template> 
</xsl:stylesheet> 

그러나 그래서 예를 들어 입력 XML을 제공하십시오 여기에 XSL입니다 우리가 확인할 수있는 샘플 입력에

, 이것은 생산이와

<xsl:sort select="."/> 

:

<xsl:sort select="count(key('niche', .))" order="descending" data-type="number"/> 

<table border="1"> 
    <tr> 
    <td>a</td> 
    <td>1</td> 
    </tr> 
    <tr> 
    <td>b</td> 
    <td>2</td> 
    </tr> 
    <tr> 
    <td>c</td> 
    <td>3</td> 
    </tr> 
</table> 

대신 일종의 가장 높은에서 가장 낮은 발생 횟수, 당신은이 라인을 대체 할 수하기 위해

+0

가장 높은 숫자로 정렬하려면 어떻게해야합니까? 예 : c 3 b 2 a 1 – Accolade

+1

내 대답이 업데이트되었습니다. 끝에있는 주석을 확인하십시오. – JLRishe

+0

작동하지 않는 것 같습니까? 왼쪽 열을 순서대로 출력하는 것 같습니까? 예 : a 1 b 2 c 3 – Accolade

관련 문제