2012-06-11 5 views
0

XSLT를 사용하여 XML을 HTML로 변환합니다. 의 출력에는 서로 연결된 두 개의 HTML 파일이 있어야합니다. 첫 번째 html에는 데이터 목록이 있으며 특정 데이터를 클릭하면 해당 html 파일의 세부 정보를 가져와야합니다. 나는 이것을 위해 xslt를 사용할 필요가있다.출력으로 여러 html과 하나 xsl

나는 여러 HTML을 생성하기 위해 색슨을 사용했지만 링크 기능을 수행 할 수있다. 이 작업을 수행하는 방법에 대한 아이디어가 있습니까?

이것에 대해 어려운 것이없는이

<a:file> 
<a:id>33</a:id> 
<a:name>hello</a:name> 
<a:school>mumbai public</a:school> 
<a:marks>80</a:marks> 
</a:file> 

답변

2

잘 색슨 9 또는 두 개의 문서를 연결하는 등, 하나의 스타일로 여러 결과 문서를 생성 할 수있는 XSLT 2.0 프로세서와 같은 내 입력 봐, 당신은 단순히을 사용 HTML a 요소에는 href 속성이 다른 문서에 연결되어 있습니다.

특정 데이터에 대해 도움이 필요한 경우 작지만 대표적인 XML 입력 샘플과 작성하려는 HTML을 게시하십시오.

[편집]

당신이 그 a:file 요소의 부부와 함께 입력 문서가 당신이 다음과 같이 당신이를 해결할 수있는 세부 사항을 나열하는 별도의 파일에 링크 된 모든 a:names을 나열하는 하나의 주 HTML 문서를 만들 가정 :

<xsl:template match="/"> 
    <xsl:apply-templates select="//a:file" mode="doc"/> 
    <html> 
    <head> 
     <title>Example</title> 
    </head> 
    <body> 
     <h1>Data list</h1> 
     <ul> 
     <xsl:apply-templates select="//a:file"/> 
     </ul> 
    </body> 
    </html> 
</xsl:template> 

<xsl:template match="a:file"> 
    <li> 
    <a href="{a:id}.html"> 
     <xsl:value-of select="a:name"/> 
    </a> 
    </li> 
</xsl:template> 

<xsl:template match="a:file" mode="doc"> 
    <xsl:result-document href="{a:id}.html"> 
    <html> 
     <head> 
     <title>Details of <xsl:value-of select="a:name"/></title> 
     </head> 
     <body> 
     <table> 
      <thead> 
      <tr> 
      <xsl:apply-templates mode="thead"/> 
      </tr> 
      </thead> 
      <tbody> 
      <tr> 
      <xsl:apply-templates mode="doc"/> 
      </tr> 
      </tbody> 
     </table> 
     </body> 
    </html> 
    </xsl:result-document> 
</xsl:template> 

<xsl:template match="a:file/*" mode="doc"> 
    <td> 
    <xsl:value-of select="."/> 
    </td> 
</xsl:template> 

<xsl:template match="a:file/*" mode="thead"> 
    <th> 
    <xsl:value-of select="local-name()"/> 
    </th> 
</xsl:template> 

테스트되지 않았지만 아이디어를 제공해야합니다. 더 많은 도움이 필요하다면 입력과 출력을 더 자세히 보여주세요. 기본 HTML 결과 (목록 사용)와 세부 사항 파일 (표 사용)의 형식을 모두 작성해야했습니다. 전체 입력 샘플을 가정

[편집 2 는

<a:files xmlns:a="http://example.com/a"> 
<a:file> 
<a:id>33</a:id> 
<a:name>hello</a:name> 
<a:school>mumbai public</a:school> 
<a:marks>80</a:marks> 
</a:file> 
</a:files> 

이고 I는 HE 커맨드 라인은, 예를 들어하기에서 색슨 9.4 사용할 때 전체 스타일 시트 샘플을

<xsl:stylesheet 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:a="http://example.com/a" 
    exclude-result-prefixes="a" 
    version="2.0"> 

<xsl:template match="/"> 
    <xsl:apply-templates select="//a:file" mode="doc"/> 
    <html> 
    <head> 
     <title>Example</title> 
    </head> 
    <body> 
     <h1>Data list</h1> 
     <ul> 
     <xsl:apply-templates select="//a:file"/> 
     </ul> 
    </body> 
    </html> 
</xsl:template> 

<xsl:template match="a:file"> 
    <li> 
    <a href="{a:id}.html"> 
     <xsl:value-of select="a:name"/> 
    </a> 
    </li> 
</xsl:template> 

<xsl:template match="a:file" mode="doc"> 
    <xsl:result-document href="{a:id}.html"> 
    <html> 
     <head> 
     <title>Details of <xsl:value-of select="a:name"/></title> 
     </head> 
     <body> 
     <table> 
      <thead> 
      <tr> 
      <xsl:apply-templates mode="thead"/> 
      </tr> 
      </thead> 
      <tbody> 
      <tr> 
      <xsl:apply-templates mode="doc"/> 
      </tr> 
      </tbody> 
     </table> 
     </body> 
    </html> 
    </xsl:result-document> 
</xsl:template> 

<xsl:template match="a:file/*" mode="doc"> 
    <td> 
    <xsl:value-of select="."/> 
    </td> 
</xsl:template> 

<xsl:template match="a:file/*" mode="thead"> 
    <th> 
    <xsl:value-of select="local-name()"/> 
    </th> 
</xsl:template> 

</xsl:stylesheet> 

인 지금까지 파일의 수에 관한 한뿐만 아니라 모두 나를 위해 잘 작동 그래서

<html> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
     <title>Example</title> 
    </head> 
    <body> 
     <h1>Data list</h1> 
     <ul> 
     <li><a href="33.html">hello</a></li> 
     </ul> 
    </body> 
</html> 




<html> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
     <title>Details of hello</title> 
    </head> 
    <body> 
     <table> 
     <thead> 
      <tr> 

       <th>id</th> 

       <th>name</th> 

       <th>school</th> 

       <th>marks</th> 

      </tr> 
     </thead> 
     <tbody> 
      <tr> 

       <td>33</td> 

       <td>hello</td> 

       <td>mumbai public</td> 

       <td>80</td> 

      </tr> 
     </tbody> 
     </table> 
    </body> 
</html> 

다음과 같이 java -jar saxon9he.jar input.xml sheet.xsl -o:result.html 나는보고, result.html되는 과정의 기본은, 다른 하나는 33.html되는 두 개의 결과 파일을 가져 브라우저 내부에서 작업하는 링크입니다.

+0

예 저는 a와 href를 사용하여 동일하게했으나 두 번째 html에는 특정 레코드의 정보를 표시하는 방법을 사용했습니다. '세부 정보'라는 링크를 클릭한다고 가정하면 세부 정보를 클릭 할 때 모든 정보가 아닌 특정 정보 만 가져와야합니다. – user1402867

+0

나는 나의 질문을 편집하고 샘플 XML 입력을했다. 한 페이지에 모든 이름이 표시되고 이름을 클릭하면 완전한 세부 정보를 표시하는 다른 페이지로 리디렉션되어야합니다. – user1402867

+0

답변을 편집하고 접근 방법을 보여주는 코드 샘플을 추가하면 기본 변환 결과가 모든 항목을 표시하는 HTML 문서로 생성 된 다음 단일 항목의 세부 정보를 보여주는 추가 결과 문서에 연결됩니다. –