XSLT_使い方

【1)XMLのほう】

<?xml version="1.0" encoding="Shift_JIS" ?>
<PAGE>
  <EMPLOYEES>
    <EMPLOYEE>
      <EMPNO>1</EMPNO>
      <ENAME>佐野力</ENAME>
      <JOB>President</JOB>
      <HIREDATE>1990-04-01</HIREDATE>
      <SAL>10000</SAL>
      <DEPTNO>10</DEPTNO>
    </EMPLOYEE>
    <EMPLOYEE>
      <EMPNO>50</EMPNO>
      <ENAME>高橋敦子</ENAME>
      <JOB>Director</JOB>
      <MGR>1</MGR>
      <HIREDATE>1991-04-01</HIREDATE>
      <SAL>6000</SAL>
      <DEPTNO>30</DEPTNO>
    </EMPLOYEE>
    <EMPLOYEE>
      <EMPNO>1401</EMPNO>
      <ENAME>小山尚彦</ENAME>
      <JOB>Analyst</JOB>
      <MGR>50</MGR>
      <HIREDATE>1999-09-01</HIREDATE>
      <SAL>3000</SAL>
      <DEPTNO>30</DEPTNO>
    </EMPLOYEE>
  </EMPLOYEES>
</PAGE>

* * *
【2)XSLTのほう…stylesheet1.xsl】

<?xml version="1.0" encoding="Shift_JIS"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/
     1999/XSL/Transform" version="1.0">
   <xsl:output method="html" encoding="Shift_JIS"/>

  <xsl:template match="/">
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="PAGE">
    <HTML>
    <BODY>
    <xsl:apply-templates/>
    </BODY>
    </HTML>
  </xsl:template>

  <xsl:template match="EMPLOYEES">
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="EMPLOYEE">
    <xsl:value-of select="ENAME"/><BR/>
  </xsl:template>

</xsl:stylesheet>

* * *
【3)2を1に対して使うには】

1)の2行目に
<?xml-stylesheet type="text/xsl" href="stylesheet1.xsl"?>
を追加。

* * *
【4)結果】
<HTML>
<BODY>

  佐野力<BR>
  高橋敦子<BR>
  小山尚彦<BR>

</BODY>
</HTML>

というHTML文書が生成される

* * *
引用元:
http://www.atmarkit.co.jp/fxml/tanpatsu/xslt/xslt01.html
最終更新:2011年11月14日 10:31