2013년 8월 14일 수요일

[오라클자바 XML강좌]XML XSLT예제(사원리스트)

-------------
sawon.xml
-------------

오라클자바커뮤니티에서 설립한 오엔제이프로그래밍 실무교육센터
(신입사원채용무료교육, 오라클SQL, 튜닝, 힌트,자바프레임워크, 안드로이드, 아이폰, 닷넷)  


<?xml version="1.0" encoding="euc-kr"?>
<?xml-stylesheet type="text/xsl" href="Sawon.xsl" ?>
<사원리스트>
<사원>
<부서>기획부</부서>
<이름>김동유</이름>
<취미>등산</취미>
</사원>
<사원>
<부서>생산부</부서>
<이름>김생산</이름>
<취미>낚시</취미>
</사원>
</사원리스트>




-----------------------
sawon.xsl
-----------------------
<?xml version="1.0" encoding="euc-kr" ?>
<xsl:stylesheet version="1.0"    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="euc-kr"/> 
<xsl:template match="/">
  <root>
<xsl:apply-templates select="/사원리스트/사원"/>
  </root>
</xsl:template>

<xsl:template match="/사원리스트/사원" > 
<xsl:value-of select="이름"/>사원을 처리하였습니다... <br/>
    </xsl:template>
</xsl:stylesheet>


--------------
book.xml
--------------
<?xml version="1.0" encoding="euc-kr" ?>
<?xml-stylesheet type="text/xsl" href="book.xsl" ?>
<books>
<book isbn="89-314-1826-5">
<name>XML정복</name>
<publisher>영진.com</publisher>
<price>15000</price>
<url>http://www.oraclejava.co.kr</url>
<published>2002.09.01</published>
<desc>
    <keyword>XML</keyword>
    이번기회에 XML을 완전히 정복합시다~ 여러분,, 
    기회는 자주 오는것이 아닙니다.

    from jclee...
</desc>
</book>


<book isbn="02-3143-1826-7">
<name>C++정복하기</name>
<publisher>삼양사</publisher>
<price></price>
<url>http://www.oraclejava.co.kr</url>
<published>2002.12.01</published>
<desc>
<keyword>XML</keyword>
C언어는 모든프로그래밍의 기본입니다...
꾸준히,,, 공부하세요.

from jclee...
</desc>
</book>
</books>


------------------
book.css
------------------
body { background:#FFffFF; }
h1 {
font-size:14pt;
font-weight:bold;
}

th {
font-size:10pt;
font-weight:bold;
background:#00ccff;
line-height:150%;
}
td {
font-size:9pt;
font-weight:normal;
background:#ffffcc;
line-height:150%;
}



------------------
book.xsl
------------------
<?xml version="1.0" encoding="euc-kr" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" version="4.0" encoding="euc-kr"/>
<xsl:decimal-format NaN="미정"/>
<xsl:template match="/">
<html>
  <head>
<title>도서목록</title>
<link rel="stylesheet" type="text/css" href="book.css"/>
</head>
<h1>도서일람표</h1>
<table border="1">
<tr>
<th>No.</th>


<th>ISBN코드</th>
<th>서적</th>
<th>출판사</th>
<th>가격</th>
<th>발행일</th>
</tr>
<xsl:apply-templates select="books"/>
</table>
</html>
</xsl:template>

<xsl:template match="books">
      <xsl:for-each select="book">
      <xsl:sort select="date" data-type="text" order="descending"/>
      <xsl:sort select="price" data-type="number" order="ascending"/>
  <tr>
<td nowrap="nowrap">
<xsl:number value="position()" format="1"/>
</td>


<td nowrap="nowrap">
<xsl:value-of select="@isbn"/>
</td>
<td nowrap="nowrap">
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="url"/>
</xsl:attribute>
<xsl:value-of select="name"/>
</xsl:element>
</td>
<td nowrap="nowrap">
<xsl:choose>
    <!-- <xsl:when test="publisher='영진.com'"> -->    <xsl:when test="publisher[.='영진.com']">
<div style="font-style:italic;">
                <xsl:value-of select="publisher"/>
</div>
    </xsl:when>


  <xsl:otherwise>
        <xsl:value-of select="publisher"/>
  </xsl:otherwise>
</xsl:choose>
</td>
<td nowrap="nowrap">
  <xsl:value-of select="format-number(price,'###,##0')"/>
  <!-- <xsl:if test="price != ''">원</xsl:if> -->
  <xsl:if test="price[. != '']">원</xsl:if> 
  </td>
<td nowrap="nowrap">
<xsl:value-of select="published"/>
  </td>
</tr>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

댓글 없음:

댓글 쓰기