XML Note #6 XSL 기본 문법(2)


14. xsl:param

템플릿의 파라미터를 정의한다.

정의한 파라미터는 곧바로 $기호를 붙여 사용할 수 있다.

아래 예제에서 제목, 분류, 발행일, 가격은 xsl:template가 따로 정의되지 않았음에도 불구하고 그대로

사용이 가능함을 볼 수 있다. (명명된 템플릿)

- 예제:

...

<항목>

<분류>XML</분류>

<발행일>2000-01-01</발행일>

<제목>Professional XML</제목>

<가격>60,000원</가격>

</항목>

...


<xsl:template name="테이블">

<xsl:param name="alignment">center</xsl:param>

<xsl:param name="color">black</xsl:param>

<tr style="color:{$color}">

<th align="{$alignment}">

<xsl:apply-templates select="./제목"/>

</th>

<td><xsl:apply-templates select="./분류" /></td>

<td><xsl:apply-templates select="./발행일" /></td>

<td><xsl:apply-templates select="./가격" /></td>

</tr>

</xsl:template>



15. xsl:call-template

선언된 템플릿을 적용한다.

apply-templates와 다른 점은, call-template에서는 template name으로 지정한 template를 호출하는 것이고,

aplly-templates는 template match로 지정한 template를 호출한다는 점이다.

- 예제:

<xsl:for-each select="/책리스트/항목">

<xsl:choose>

<xsl:when test="contains(발행일/text(), '1999')">

<xsl:call-template name="테이블"/>

</xsl:when>

<xsl:when test="contains(발행일/text(), '2000')">

<xsl:call-template name="테이블">

<xsl:with-param name="alignment">left</xsl:with-param>

<xsl:with-param name="color">red</xsl:with-param>

</xsl:call-template>

</xsl:when>

</xsl:choose>

</xsl:for-each>


위 예제에서 contains(발행일/text(), '1999') 부분은 자주 사용되는 중요한 조건 비교문이다.



16. xsl:with-param

호출하여 사용하는 template를 새로운 param으로 지정하여 사용하고자 할 때 쓰며, param과 동일하다.

- 예제:

<xsl:call-template name="테이블">

<xsl:with-param name="alignment">left</xsl:with-param>

<xsl:with-param name="color">red</xsl:with-param>

</xsl:call-template>



17. xsl:number

해당 위치에 번호를 붙인다. 지정 가능한 포맷으로는 1), (1), 1. 등이 있다.

- 예제:

<xsl:number value="position()" format="1. "/>



18. html xmlns

XSL내에서 HTML을 사용할 때 지정하는 namespace.

- 예제:

<html xmlns="http://www.w3.org/TR/xhtml1/strict"> 

</html>



19. xsl:element

HTML 태그(요소)를 정의한다.

- 예제:

...

<이미지 src="89-7627-762-7.gif"/>

...


<xsl:template match="이미지">

<xsl:element name="img">

<xsl:attribute name="src"><xsl:value-of select="@src"/></xsl:attribute>

</xsl:element>

</xsl:template>


<xsl:apply-templates select="이미지"/>


- 예제2:

<xsl:element name="{.}">this name</xsl:element>


다음의 XML이 있을 때,

<NAME>thermidor</NAME>


위 예제2는 아래와 같이 변환시킨다.

<thermidor>this name</thermidor>



20. xsl:copy-of

선택된 노드를 그대로 현재 위치에 복사해 쓴다.

- 예제:

<xsl:copy-of select="."/> 



21. xsl:variable

XSL에서 사용할 변수를 정의하여 사용할 수 있게 한다.

- 예제:

<xsl:variable name="para-font-size">12pt</xsl:variable>


<xsl:template match="para">

  <fo:block font-size="{$para-font-size}">

     <xsl:apply-templates/>

  </fo:block>

</xsl:template>



'Tech: > XML·XSL' 카테고리의 다른 글

XML 기본개념: 추가  (0) 2008.06.26
XSL 사용예제 - DNA 구조 ^^;  (0) 2008.06.26
XMLHTTP 사용시 주의사항  (0) 2008.06.26
DOM(2)  (0) 2008.06.26
DOM(1)  (0) 2008.06.26


Posted by 떼르미
,


자바스크립트를 허용해주세요!
Please Enable JavaScript![ Enable JavaScript ]