xsl:call-template 예제
<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="makeTable.xsl"?> <Persons> <Person name="Tom" age="19" department="Sales" /> <Person name="Jane" age="23" department="Development" /> <Person name="Sam" age="14" department="HumanResource" /> <Person name="Paul" age="40" department="Sales" /> <Person name="Kazuya" age="28" department="HumanResource" /> <Person name="Baek doo san" age="32" department="Development" /> </Persons> |
makeTable.xml
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"> <xsl:template match="/Persons"> <table border="1" cellpadding="1" cellspacing="1"> <xsl:apply-templates select="/Persons/Person"/> </table> </xsl:template> <xsl:template match="/Persons/Person"> <xsl:call-template name="makeTable"> <xsl:with-param name="age"> <xsl:value-of select="./@age"/> </xsl:with-param> <xsl:with-param name="department"> <xsl:value-of select="./@department"/> </xsl:with-param> </xsl:call-template> </xsl:template> <xsl:template name="makeTable"> <xsl:param name="age"/> <xsl:param name="department"/> <tr> <td> <xsl:element name="font" > <xsl:attribute name="color">blue</xsl:attribute> <xsl:value-of select="./@name" /> </xsl:element> </td> <td> <xsl:value-of select="$age" /> </td> <td> <xsl:choose> <xsl:when test="$age > 20">Adult</xsl:when> <xsl:otherwise>Student</xsl:otherwise> </xsl:choose> </td> <td> <xsl:value-of select="$department" /> </td> <td> <xsl:choose> <xsl:when test="$department='Development'"><xsl:text disable-output-escaping="yes">Hard&nbsp;Work</xsl:text></xsl:when> <xsl:otherwise>Easy</xsl:otherwise> </xsl:choose> </td> </tr> </xsl:template> </xsl:stylesheet> |
결과 화면
Tom | 19 | Student | Sales | Easy |
Jane | 23 | Adult | Development | Hard Work |
Sam | 14 | Student | HumanResource | Easy |
Paul | 40 | Adult | Sales | Easy |
Kazuya | 28 | Adult | HumanResource | Easy |
Baek doo san | 32 | Adult | Development | Hard Work |
keywords : xsl:template; xsl:call-template; xsl:with-param; xsl:param; xsl:choose; xsl:text