2017-10-13 1 views
1

이 작업에 큰 문제가 있으며 정렬 작업을 수행 할 수 없습니다.XSLT 외부 문서의 정보로 테이블 정렬

XSLT에서 .XSL을 가져 오는 테이블을 정렬하려고합니다. 이 .XSL에는 두 개의 외부 .XSL이 참조되어 있습니다. 출력은 html이어야합니다.

mainXSL.xsl

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:output method="html" media-type="image/svg" indent="yes" encoding="UTF-8"/> 

       <xsl:variable name="fileA" select="document(/importFiles/docs/@fileA)" /> 
       <xsl:variable name="fileB" select="document(/importFiles/docs/@fileB)" /> 
    <xsl:template match="/"> 
     <html> 
      <head> 
       <title> 
        Task1 
       </title> 
      </head>   
       <body> 
        <table align="center" border="1"> 
         <tr> 
          <th>column_1</th> 
          <th>column_2</th> 
         </tr> 

         <xsl:for-each select="$fileA/letters/letter"> 
          <xsl:sort select="." order="ascending"/> 
           <xsl:variable name="current_node" select="position()"/> 
            <tr>         
             <td class="_fileA"><xsl:value-of select="." /></td> 
             <td class="_fileB"><xsl:value-of select="$fileB//animal[$current_node]" /></td> 
            </tr> 
          </xsl:for-each> 
        </body> 
       </html> 
</xsl:template> 

이 Index.xml

<?xml version="1.0" encoding="UTF-8"?> 
<?xml-stylesheet type="text/xsl" href="mainXSL.xsl"?> 

<importFiles> 
    <docs fileA = "fileA.xml" /> 
    <docs fileB = "fileB.xml" /> 
</importFiles> 

fileA.xml

<?xml version="1.0" encoding="UTF-8"?> 

     <letters> 
      <letter>A</letter> 
      <letter>C</letter> 
      <letter>B</letter> 
      <letter>E</letter> 
      <letter>D</letter> 
     </letters> 

fileB.xml

<?xml version="1.0" encoding="UTF-8"?> 

     <animals> 
      <animal>dog</animal> 
      <animal>horse</animal> 
      <animal>cow</animal> 
      <animal>snake</animal> 
      <animal>spider</animal> 
     </animals> 
- 개

B - 말

A : fileA.xml에서

그래서 편지는 내가 뭘 이제 얻을 것은 테이블 fileB.xml

에서 같은 행에 동물 프로그램에 부착된다

C - 소

D - 뱀

E - 거미

는 내가 뭘 얻고 싶은 것은 :

A - 개

B - 소

C - 말

D - 거미

E - 뱀

내가 할 수있는 for-each 루프 다음에 열을 함께 정렬하는 방법, column_1 만 알아내는 방법. 비슷한 문제를 찾으려고했지만 아무 소용이 없습니다. 나는 전에 비슷한 질문을 올렸지 만 정확한 답을 얻었지만 숫자를 문자로 편집하는 것을 잊어 버렸다. 숫자를 사용하면 position()을 사용하는 것이 더 쉬워집니다. 이 경우 position()이 인덱스로 사용될 수 있다고 가정하지만 긴 장면입니다. 나는 이것이 더 간단한 해결책을 가지고 있다고 믿는다.

답변

2

변경

<xsl:variable name="current_node" select="position()"/> 

<xsl:variable name="orig-pos"><xsl:number/></xsl:variable> 

에 다음

<xsl:value-of select="$fileB//animal[position() = $orig-pos]" /> 
+0

당신 경을 사용, 진정한 구세주입니다! 감사합니다! –