XML/XML

<xsl:template><xsl:value-of><xsl:for-each><xsl:sort><xsl:if>...

본클라쓰 2009. 11. 6. 17:57

1. <xsl:template> 요소


<xsl:template match="/"> 이런 방법으로 작성했다면 XML 문서의 요소들을 "/"문자를 기준으로 분리함을 나타냅니다.




2. <xsl:value-of> 요소


 XML 요소의 특정 값을 얻을 때 사용하는 요소입니다.

<?xml version="1.0"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


<xsl:template match="/">

    <html>

    <body>

    <h2>내 시디 목록</h2>

        <table>

            <tr>

                <td>제목</td>

                <td>가수</td>

            </tr>

            <tr>

                <td><xsl:value-of select="catalog/cd/title"/></td>

                <td><xsl:value-of select="catalog/cd/artist"/></td>

            </tr>

        </table>

    </body>

    </html>

</xsl:template>

</xsl:stylesheet>



3. <xsl:for-each> 요소 : 반복

<?xml version="1.0"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


<xsl:template match="/">

    <html>

    <body>

    <h2>내 시디 목록</h2>

        <table>

            <tr>

                <td>제목</td>

                <td>가수</td>

            </tr>

            <xsl:for-each select="catalog/cd">

            <tr>

                <td><xsl:value-of select="catalog/cd/title"/></td>

                <td><xsl:value-of select="catalog/cd/artist"/></td>

            </tr>

            <xsl:for-each>

        </table>

    </body>

    </html>

</xsl:template>

</xsl:stylesheet>


<xsl:for-each>에 조건을 주는 방법

<xsl:for-each select="catalog/cd[artist="소녀시대"]">




4. <xsl:sort>  :  정렬

<?xml version="1.0"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


<xsl:template match="/">

    <html>

    <body>

    <h2>내 시디 목록</h2>

        <table>

            <tr>

                <td>제목</td>

                <td>가수</td>

            </tr>

            <xsl:for-each select="catalog/cd">

            <xsl:sort select="artist"/>

            <tr>

                <td><xsl:value-of select="catalog/cd/title"/></td>

                <td><xsl:value-of select="catalog/cd/artist"/></td>

            </tr>

            <xsl:for-each>

        </table>

    </body>

    </html>

</xsl:template>

</xsl:stylesheet>




5. <xsl:if>  :  조건

<?xml version="1.0"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


<xsl:template match="/">

    <html>

    <body>

    <h2>내 시디 목록</h2>

        <table>

            <tr>

                <td>제목</td>

                <td>가수</td>

            </tr>

            <xsl:for-each select="catalog/cd">

            <xsl:if test="year > 2009">

            <tr>

                <td><xsl:value-of select="catalog/cd/title"/></td>

                <td><xsl:value-of select="catalog/cd/artist"/></td>

            </tr>

            </xsl:if>

            <xsl:for-each>

        </table>

    </body>

    </html>

</xsl:template>

</xsl:stylesheet>





6. <xsl:choose> : if else 문

<?xml version="1.0"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


<xsl:template match="/">

    <html>

    <body>

    <h2>내 시디 목록</h2>

        <table>

            <tr>

                <td>제목</td>

                <td>가수</td>

            </tr>

            <xsl:for-each select="catalog/cd">

            <xsl:choose>

                <xsl:when test="year %gt; 2009">

                    <tr>

                        <td><xsl:value-of select="catalog/cd/title"/></td>

                        <td><xsl:value-of select="catalog/cd/artist"/></td>

                   </tr>

                 </xsl:when>

                 <xsl:otherwise>

                    <tr>

                        <td>없네염</td>

                        <td>우짜죠</td>

                   </tr>

                 </xsl:thoerwise>

            <xsl:choose>

        </table>

    </body>

    </html>

</xsl:template>

</xsl:stylesheet>



'XML > XML' 카테고리의 다른 글

엘레멘트 정의 방법  (0) 2010.09.12
XML 문서의 트리구조  (0) 2010.08.30
XSLT 선언하여 문서에 적용하기  (0) 2009.11.06
XSLT (EXtensible Stylesheet Language) 설명  (0) 2009.11.06
XML 문서의 엘레멘트와 속성  (0) 2009.09.08