XSLT XSL xml programming 1 Contents n XSL

  • Slides: 103
Download presentation
XSLT와 XSL xml programming 1

XSLT와 XSL xml programming 1

Contents n XSL이란? n XSLT란? n XSL과 XSLT 비교 n 응용사례 xml programming 2

Contents n XSL이란? n XSLT란? n XSL과 XSLT 비교 n 응용사례 xml programming 2

Cont. xml programming 4

Cont. xml programming 4

Cont. n baseball. xml과 baseball. fo 비교 n baseball. xml • <title>신나는 프로야구!</title> n

Cont. n baseball. xml과 baseball. fo 비교 n baseball. xml • <title>신나는 프로야구!</title> n baseball. fo • <fo: block text-align="center" font-weight="bold" fontsize="30 pt" font-family="Helvetica, Arial, sans-serif" space-after="30 pt" > 신나는 프로야구! </fo: block> xml programming 6

어떻게 변환시킬 것인가? n Transformation? n 변환… 직접 XML 문서를 변환 XML 문서 XSLT

어떻게 변환시킬 것인가? n Transformation? n 변환… 직접 XML 문서를 변환 XML 문서 XSLT Processor HTML , PDF… XSLT 문서 xml programming 7

XSLT란? n XML to XSL n XML to XML n XML to Other Format…

XSLT란? n XML to XSL n XML to XML n XML to Other Format… n n XML to HTML XML to WML XML to RTF XML to etc… xml programming 8

Example XSL 문서 XML 문서 XSLT Processor 다른 형태의 XML문서 HTML XSLT 문서 WML

Example XSL 문서 XML 문서 XSLT Processor 다른 형태의 XML문서 HTML XSLT 문서 WML PDF 각 각 의 V i e w e r RTF, DOC, HWP … xml programming 9

XSLT와 XSL 비교 n Transformation? n n 변환… Formatting? n Presentation 능력을 지닌 언어

XSLT와 XSL 비교 n Transformation? n n 변환… Formatting? n Presentation 능력을 지닌 언어 • HTML, PDF, HWP, DOC, RTF… xml programming 10

… n Formatting Language!!! n n n Presentation 능력을 지닌 언어 XSL, HTML, PDF,

… n Formatting Language!!! n n n Presentation 능력을 지닌 언어 XSL, HTML, PDF, HWP, DOC, RTF… Transformation Language!!! n n XML문서를 다른 Formatting Language로 바꾸는 역할을 하는 언어. XSLT xml programming 11

Cont. xml programming 12

Cont. xml programming 12

XSLT의 응용사례 n Data의 변환 a. XSL XML b. XSLT Processor c. XSL xml

XSLT의 응용사례 n Data의 변환 a. XSL XML b. XSLT Processor c. XSL xml programming 13

Getting started with XSL n 간단한 예제 <? xml version=“ 1. 0”? > <?

Getting started with XSL n 간단한 예제 <? xml version=“ 1. 0”? > <? xml-stylesheet type=“text/xsl” href=“hello. xsl”? > <greetingk>Hello world</greeting> <? xml version=“ 1. 0”? > <xsl: stylesheet xmlns: xsl=“http: //www. w 3. org/1999/XSL/Transform” version=“ 1. 0”> <xsl: template match=“/”> <html><head><title>Greeting</title></head> <body><p>Words of greeting : <b><i><u><xsl: value-of select=“greeting”/></u></i></b> </p></body></html> </xsl: template> <xsl: stylesheet> xml programming 15

Template(틀? ) n template의 개념. xml programming 16

Template(틀? ) n template의 개념. xml programming 16

Template n 스타일시트를 이루는 가장 기본적인 단위 <? xml version=“ 1. 0” ? >

Template n 스타일시트를 이루는 가장 기본적인 단위 <? xml version=“ 1. 0” ? > <xsl: stylesheet version=“ 1. 0” xmlns: xsl=http: //www. w 3. org/1999/XSL/Transform> <xsl: template match=“/”> <HTML> <BODY> <xsl: for-each select=“/strings/s”> <p><xsl: value-of select=“. ”/></p> </xsl: for-each> </BODY> </HTML> </xsl: template> </xsl: stylesheet> n 템플리트의 구성 n n 템플리트가 적용될 소스 트리 부분 결과 트리로 삽입되어지는 부분 xml programming 17

to. HTML. xsl <xsl: template match=“/”> <html> <head></head> <body> XSLT프로세서 결과물 <xsl: apply-templates/> </body>

to. HTML. xsl <xsl: template match=“/”> <html> <head></head> <body> XSLT프로세서 결과물 <xsl: apply-templates/> </body> <html> </xsl: template> <head></head> … <body> class. xml </body> </html> Document(=/) 강좌 이름=“XML” 강사 이름 학생 xml programming 19

to. HTML. xsl <xsl: template match=“/”> … <xsl: apply-templates/> … </xsl: template> <xsl: template

to. HTML. xsl <xsl: template match=“/”> … <xsl: apply-templates/> … </xsl: template> <xsl: template match=“강좌”> <h 1><p align=“CENTER”> <xsl: value-of select=“@이름”/> </p></h 1> <table align=“center” border=“ 1”> <xsl: apply-templates/> </table> </xsl: template> XSLT프로세서 결과물 <html> <head></head> <body> Apply-templates </body> Lab. xml </html> Document(=/) <h 1><p align=“CENTER”> XML </p></h 1> <table align=“center” border=“ 1”> 강좌 이름=“XML” 강사 Apply-templates </table> 이름 학생 xml programming 20

지역 경로 1. 도큐먼트(루트) 1. 2. 엘레먼트 지정 1. 2. 3. <xsl: template match=“/”>

지역 경로 1. 도큐먼트(루트) 1. 2. 엘레먼트 지정 1. 2. 3. <xsl: template match=“/”> <xsl: template match=“/학생”> <xsl: template match=“학생”> 경로표현 1. 2. <xsl: template match=“/학생/이름”> <xsl: template match=“학생/이름”> xml programming 22

Cont. 2. 와일드 카드(*) 1. 2. 3. <xsl: template match=“*”> <xsl: template match=“@*”> <xsl:

Cont. 2. 와일드 카드(*) 1. 2. 3. <xsl: template match=“*”> <xsl: template match=“@*”> <xsl: for-each select=“*”> xml programming 25

노드 함수들 n name() n node() n processing-instruction() n comment() n text() xml programming

노드 함수들 n name() n node() n processing-instruction() n comment() n text() xml programming 27

Cont. n name() : 엘레먼트의 이름을 반환한다. n n <xsl: template match=“name”> <xsl: for-each

Cont. n name() : 엘레먼트의 이름을 반환한다. n n <xsl: template match=“name”> <xsl: for-each select=“*”> <p><xsl: value-of select=“name()”/></p> </xsl: for-each> </xsl: template> node() n n 노드 자신을 반환한다. 쓰지 않는다. xml programming 28

Cont. n n processing-instruction() n <xsl: template match=“processing-instruction()”> <xsl: value-of select=“. ”/> </xsl: template>

Cont. n n processing-instruction() n <xsl: template match=“processing-instruction()”> <xsl: value-of select=“. ”/> </xsl: template> n <xsl: template match=“processing-instruction(‘stylesheet’)”> <xsl: value-of select=“. ”/> </xsl: template> comment() n <xsl: template match=“comment()”> <xsl: value-of select=“. ”/> </xsl: template> xml programming 29

Cont. n text() n <parent> This is some text. <child>And this is some more

Cont. n text() n <parent> This is some text. <child>And this is some more text</child> </parent> n <xsl: template match=“parent”> <xsl: value-of select=“. ”/> </xsl: template> n <xsl: template match=“parent”> <xsl: value-of select=“text()”/> </xsl: template> xml programming 30

Cont. n <xsl: template match=“parent”> <xsl: value-of select=“. ”/> </xsl: template> • 결과: This

Cont. n <xsl: template match=“parent”> <xsl: value-of select=“. ”/> </xsl: template> • 결과: This is some text. And this is some more text n <xsl: template match=“parent”> <xsl: value-of select=“text()”/> </xsl: template> • 결과: This is some text. xml programming 31

위치지정 함수들 n position() n last() n count() xml programming 32

위치지정 함수들 n position() n last() n count() xml programming 32

Cont. n position() n 노드 집합 안에서 노드의 위치를 도큐먼트 순으로 얻기 위해 사용된다.

Cont. n position() n 노드 집합 안에서 노드의 위치를 도큐먼트 순으로 얻기 위해 사용된다. n 예제 • <nodes> <node>a</node> <node>b</node> <node>c</node> </nodes> • <xsl: template match=“/nodes/node”> • <xsl: template match=“/nodes/node[position()=2]”> • <xsl: template match=“/nodes/node[2]”> xml programming 33

산술 함수들 n number() n sum() xml programming 35

산술 함수들 n number() n sum() xml programming 35

Cont. n number() n n Character값을 숫자값으로 변환한다. 예제 • <element>256</element> • <xsl: if

Cont. n number() n n Character값을 숫자값으로 변환한다. 예제 • <element>256</element> • <xsl: if test=“number(@Security)”> n sum() n n 선택된 노드들의 산술값을 더해서 반환한다. 예제 • <xsl: value-of select=“sum(/nodes/node)”/> xml programming 36

Boolean 함수들 n boolean() n not() n true() n false() xml programming 37

Boolean 함수들 n boolean() n not() n true() n false() xml programming 37

Cont. n 예제 • <person> <name>YS</name> <addr>KOREA</addr> </person> • <xsl: template match=“person”> <xsl: if

Cont. n 예제 • <person> <name>YS</name> <addr>KOREA</addr> </person> • <xsl: template match=“person”> <xsl: if test=“boolean(name)”> <!--여기서 작업을 처리한다--> </xsl: if> </xsl: template> xml programming 39

Cont. n not() n n 결과 값을 반대로 변환해서 반환한다. 예제 • not(boolean(name)) n

Cont. n not() n n 결과 값을 반대로 변환해서 반환한다. 예제 • not(boolean(name)) n true(), false() n 항상 true값과 false값을 반환한다. xml programming 40

문자열 함수들 n string() n string-length() n concat() n contains() n starts-with() n substring-after()

문자열 함수들 n string() n string-length() n concat() n contains() n starts-with() n substring-after() n substring-before() n translate() xml programming 41

Cont. n translate() n 문자열을 변환한다. n 예제 • translate(‘QLSN’, ‘ABCDEFGHIJKLMNOPQRSTUVWXYZ’, ‘zyxwvutsrqpomnlkjihgfedcba’) john 반환

Cont. n translate() n 문자열을 변환한다. n 예제 • translate(‘QLSN’, ‘ABCDEFGHIJKLMNOPQRSTUVWXYZ’, ‘zyxwvutsrqpomnlkjihgfedcba’) john 반환 n 예제(대소문자 변환) • translate(‘YSJUNG', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') ‘ysjung’ 반환 xml programming 45

Cont. n 활용예제 n 예제 : 공백을 더하기 기호로 바꿀때 • translate(‘This is string’,

Cont. n 활용예제 n 예제 : 공백을 더하기 기호로 바꿀때 • translate(‘This is string’, ‘ ‘, ‘+’) n 예제 : XSLT에서 활용사례 • <xsl: value-of select= “Translate(. , ‘abcdefghijklmnopqrstuvwxyz’, ‘ABCDEFGHIJKLMNOPQRSTUVWXYZ’)” /> xml programming 46

축을 중심으로한 관계 n 13개의 정의된 축 n n n n self 축 child

축을 중심으로한 관계 n 13개의 정의된 축 n n n n self 축 child 축 descendant-or-self 축 parent 축 ancestor-or-self 축 following-sibling 축 preceding-sibling 축 following 축 preceding 축 attribute 축 namespace 축 xml programming 48

Cont. n attribute 축 n n n 속성들을 포함하는 축이다. ‘@’와 같은 의미 namespace

Cont. n attribute 축 n n n 속성들을 포함하는 축이다. ‘@’와 같은 의미 namespace 축 xml programming 51

Cont. n 사용 방법 n n 예제 n n n 축이름: : 노드이름 child:

Cont. n 사용 방법 n n 예제 n n n 축이름: : 노드이름 child: : order(order) descendant-or-self: : description (. //description) order/attribute: : number (order/@number) //date/parent: : order (//date/. . /order) /order/descendant: : description //quantity/ancestor: : order //description/following-sibling: : quantity //quantity/preceding-sibling: : description /order/date/following: : * /order/item/preceding: : * 실습하기!!! xml programming 52

쉬어가기! xml programming 53

쉬어가기! xml programming 53

XSLT문서 XSLT 프로세서 결과 문서 XML 문서 xml programming 57

XSLT문서 XSLT 프로세서 결과 문서 XML 문서 xml programming 57

XSLT 프로세서 결과 문서 XML 문서 XSLT문서 xml programming 58

XSLT 프로세서 결과 문서 XML 문서 XSLT문서 xml programming 58

XML문서 XSLT 프로세서 결과 문서 XSLT문서 xml programming 59

XML문서 XSLT 프로세서 결과 문서 XSLT문서 xml programming 59

Template n 스타일시트를 이루는 가장 기본적인 단위 <? xml version=“ 1. 0” ? >

Template n 스타일시트를 이루는 가장 기본적인 단위 <? xml version=“ 1. 0” ? > <xsl: stylesheet version=“ 1. 0” xmlns: xsl=http: //www. w 3. org/1999/XSL/Transform> <xsl: template match=“/”> <HTML> <BODY> <xsl: for-each select=“/strings/s”> <p><xsl: value-of select=“. ”/></p> <xsl: for-each> </BODY> </HTML> </xsl: template> </xsl: stylesheet> n 템플리트의 구성 n n 템플리트가 적용될 소스 트리 부분 결과 트리로 삽입되어지는 부분 xml programming 60

Cont. n 적용 우선 순위? n n <doc>hi~~ <greeting>안뇽!!!</greeting> </do 0 c> <!-- 무엇이

Cont. n 적용 우선 순위? n n <doc>hi~~ <greeting>안뇽!!!</greeting> </do 0 c> <!-- 무엇이 매칭될까? --> <xsl: template match="greeting"> <g 1><xsl: value-of select=". "/></g 1> </xsl: template> <xsl: template match="/doc/greeting"> <g 2><xsl: value-of select=". "/></g 2> </xsl: template> xml programming 61

XLST의 구성 요소들 n n n n <xsl: stylesheet> <xsl: template> <xsl: apply-templates> <xsl:

XLST의 구성 요소들 n n n n <xsl: stylesheet> <xsl: template> <xsl: apply-templates> <xsl: value-of> <xsl: output> <xsl: element> <xsl: attribute-set> <xsl: text> <xsl: if> <xsl: choose> <xsl: for-each> <xsl: copy-of> <xsl: copy> <xsl: sort> xml programming 62

<xsl: stylesheet> n <xsl: stylesheet version=“ 1. 0” xmlns: xsl=“http: //www. w 3. org/1999/XSL/Transform”>

<xsl: stylesheet> n <xsl: stylesheet version=“ 1. 0” xmlns: xsl=“http: //www. w 3. org/1999/XSL/Transform”> n 루트 엘리먼트의 역할을 한다. n 네임스페이스를 정확히 기재해야 함 • XSLT프로세서가 XSLT태그를 구별하는 방법 n verions과 xmlns: xsl 은 반드시 필요한 요소 xml programming 63

<xsl: template> n XSLT 스타일시트를 구성하는 기본 엘레먼트 n <xsl: template match=“Xpath pattern” name=“template

<xsl: template> n XSLT 스타일시트를 구성하는 기본 엘레먼트 n <xsl: template match=“Xpath pattern” name=“template name” priority=“number” mode=“mode name”> n XSLT 스타일시트를 구성하는 기본 엘레먼트 xml programming 64

<xsl: value-of> n Select 속성에 지정된 Xpath expression에 정해진 값을 찾기 위 해 문맥

<xsl: value-of> n Select 속성에 지정된 Xpath expression에 정해진 값을 찾기 위 해 문맥 노드를 탐색하여 결과 트리에 삽입한다. n <xsl: value-of select=“Xpath expression” disable-output-escaping=“yes or no” n Select의 예제: • <xsl: value-of select=“. ”> • <xsl: value-of select=“customer/@id”> xml programming 67

Cont. n Disable-output-escaping은 “& ” 나 “&lt”와 같은 이스케 이프 문자대신, “&” 나 “<“

Cont. n Disable-output-escaping은 “& ” 나 “&lt”와 같은 이스케 이프 문자대신, “&” 나 “<“ 문자를 출력하도록 지시. • 기본적으로 “no”로 설정 -> 그대로 출력 • “yes” -> 변환하여 출력 n <xsl: value-of select=". " disable-output-escaping="no" /> • & n <xsl: value-of select=". " disable-output-escaping=“yes" /> • & n 실습해보기!!! xml programming 68

<xsl: output> n n XSLT는 XML이나 HTML, 그리고 Text로 출력할 수 있다. <xsl: output>은

<xsl: output> n n XSLT는 XML이나 HTML, 그리고 Text로 출력할 수 있다. <xsl: output>은 사용할 방법을 지정할 수 있게 한다. 만약 이 엘레먼트가 스타일시트에 포함된다면 반드시 <xsl: template> 자식이 되어야 한다. <xsl: output method=“xml or html or text” version=“version” encoding=“encoding” omit-xml-declaration=“yes or no” standalone=“yes or no” cdata-section-elements=“CDATA section” indent=“yes or no”/> xml programming 69

Cont. n method • XML, HTML, TEXT 등 출력형태 지정 n version : XML일

Cont. n method • XML, HTML, TEXT 등 출력형태 지정 n version : XML일 때만 사용 encoding : XML일 때만 사용 standalone : XML일 때만 사용 n omit-xml-declaration n n • XML 선언부를 생략할 수 있다. (기본값 “no”) n cdata-section-elements • 해당되는 값을 cdata section에 넣는다. (? ? ? XSLT가 잘 지원 못함) n indent • 보기 좋은 공백을 만들어 준다. xml programming 71

<xsl: element> n Element를 만들 수 있는 기능을 제공 n <xsl: element name=“element name”

<xsl: element> n Element를 만들 수 있는 기능을 제공 n <xsl: element name=“element name” use-attribute-sets=“attribute set names”> n Name • 엘레먼트의 태그 이름을 정해 준다 n 사용 예제 • <xsl: element name=“이름”>홍길동</xsl: element> • <이름>홍길동</이름> xml programming 72

Cont. n 동적 생성 • <xsl: element name=“{. }”>My text</xsl: element> Xpath expression n

Cont. n 동적 생성 • <xsl: element name=“{. }”>My text</xsl: element> Xpath expression n 예제 • <xsl: template match=“name”> <xsl: element name=“{. }”>인간성좋음</xsl: element> </xsl: template> • <name>홍길동</name> n 결과 • <홍길동>인간성좋음</홍길동> xml programming 73

Cont. n 실습 n Attribute를 가지고 있는 XML문서를 Element를 가진 XML문서 로 바꾸어 보자.

Cont. n 실습 n Attribute를 가지고 있는 XML문서를 Element를 가진 XML문서 로 바꾸어 보자. <? xml version="1. 0"? > <people> <name first="John" middle="Fitzgerald Johansen" last="Doe"/> <name first="Franklin" middle="D. " last="Roosevelt"/> <name first="Alfred" middle="E. " last="Neuman"/> <name first="John" middle="Q. " last="Public"/> <name first="Jane" middle="" last="Doe"/> </people> xml programming 74

<? xml version="1. 0" encoding="UTF-16"? > <people> <name> <first>John</first> <middle>Fitzgerald Johansen</middle> <last>Doe</last> </name> Cont.

<? xml version="1. 0" encoding="UTF-16"? > <people> <name> <first>John</first> <middle>Fitzgerald Johansen</middle> <last>Doe</last> </name> Cont. <name> <first>Franklin</first> <middle>D. </middle> <last>Roosevelt</last> </name> <first>Alfred</first> <middle>E. </middle> <last>Neuman</last> </name> <first>John</first> <middle>Q. </middle> <last>Public</last> </name> <first>Jane</first> <middle></middle> <last>Doe</last> </name> </people> xml programming 75

<xsl: attribute> n Attribute를 만들 수 있는 기능을 제공 n <xsl: attribute name=“attribute name”>

<xsl: attribute> n Attribute를 만들 수 있는 기능을 제공 n <xsl: attribute name=“attribute name”> n name • Attribute의 이름을 정해 준다 n 사용 예제 • <name> <xsl: attribute name=“번호”>123</xsl: attribute> 홍길동 </name> • <name 번호=“ 123”>홍길동</name> xml programming 76

Cont. n 동적 생성의 예 • <name> <xsl: attribute name=“{. }”>123</xsl: attribute> 홍길동 </name>

Cont. n 동적 생성의 예 • <name> <xsl: attribute name=“{. }”>123</xsl: attribute> 홍길동 </name> ※ 엘레먼트뒤에서 사용되었다. n 잘못된 예 • <name> 홍길동 <xsl: attribute name=“{. }”>123</xsl: attribute> </name> ※ PCDATA의 어트리뷰트가 되려고 한다!!? ? xml programming 77

<xsl: attribute-set> n Attribute 그룹을 만드는 기능 제공 n <xsl: attribute-set name=“Id. Size”> <xsl:

<xsl: attribute-set> n Attribute 그룹을 만드는 기능 제공 n <xsl: attribute-set name=“Id. Size”> <xsl: attribute name=“id”>123</xsl: attribute> <xsl: attribute name=“Size”>100</xsl: attribute> </xsl: attribute-set> xml programming 78

Cont. <? xml version="1. 0" encoding="UTF-16"? > <people> <name> <first>John</first> <middle>Fitzgerald Johansen</middle> <last>Doe</last> </name>

Cont. <? xml version="1. 0" encoding="UTF-16"? > <people> <name> <first>John</first> <middle>Fitzgerald Johansen</middle> <last>Doe</last> </name> <first>Franklin</first> <middle>D. </middle> <last>Roosevelt</last> </name> <first>Alfred</first> <middle>E. </middle> <last>Neuman</last> </name> <first>John</first> <middle>Q. </middle> <last>Public</last> </name> <first>Jane</first> <middle></middle> <last>Doe</last> </name> </people> xml programming 80

Cont. n 다음과 같이 바꾸어라. <? xml version="1. 0"? > <people> <name first="John" middle="Fitzgerald

Cont. n 다음과 같이 바꾸어라. <? xml version="1. 0"? > <people> <name first="John" middle="Fitzgerald Johansen" last="Doe"/> <name first="Franklin" middle="D. " last="Roosevelt"/> <name first="Alfred" middle="E. " last="Neuman"/> <name first="John" middle="Q. " last="Public"/> <name first="Jane" middle="" last="Doe"/> </people> xml programming 81

<xsl: text> n 단순한 Text(PCDATA)를 결과 트리에 삽입하는 기능 제공 n <xsl: text disable-output-escaping=“yes

<xsl: text> n 단순한 Text(PCDATA)를 결과 트리에 삽입하는 기능 제공 n <xsl: text disable-output-escaping=“yes or no” /> n 예제 • <xsl: value-of select=“’john’”/> <xsl: value-of select=“’Fitzgerald Johansen’”/> • <xsl: value-of select=“’Deo’”> • 결과 : john. Fitzgerald. Johansen. Doe • 원하는 결과 • john Fitzgerald Johansen Doe xml programming 82

<xsl: choose> n Boolean값에 의해 여러개중에 하나가 선택되어져 실행된다. 무조건 한 번 실행되어지면 choose는

<xsl: choose> n Boolean값에 의해 여러개중에 하나가 선택되어져 실행된다. 무조건 한 번 실행되어지면 choose는 제어권을 잃는다. n <xsl: choose> <xsl: when test = “boolean expression”> <xsl: otherwise> </xsl: choose> n 예제 • <xsl: choose> <xsl: when test = “number[. > 2000]A big number </xsl: when> <xsl: when test = “number[. > 1000]A medium number</xsl: when> <xsl: otherwise>A small number</xsl: otherwise> <xsl: choose> xml programming 84

Cont. n 실습 n 다음의 XSLT문서를 for-each를 사용해서 고치시오. <? xml version="1. 0"? >

Cont. n 실습 n 다음의 XSLT문서를 for-each를 사용해서 고치시오. <? xml version="1. 0"? > <xsl: stylesheet version="1. 0" xmlns: xsl="http: //www. w 3. org/1999/XSL/Transform"> <xsl: output method="xml" indent="yes"/> <xsl: template match="/"> <people> <xsl: apply-templates select="/people/name"/> </people> </xsl: template> <xsl: template match="name"> <name> <xsl: apply-templates select="@*"/> </name> </xsl: template> <xsl: template match="@*"> <xsl: element name="{name()}"><xsl: value-of select=". "/></xsl: element> </xsl: template> </xsl: stylesheet> xml programming 86

Cont. n 예제 • <name> <first>YS</first> <last>Jung</last> </name> • <xsl: template match=“name”> <xsl: copy

Cont. n 예제 • <name> <first>YS</first> <last>Jung</last> </name> • <xsl: template match=“name”> <xsl: copy /> </xsl: template> n 결과 • <name/> xml programming 89

Cont. n 예제 • <name> <first>YS</first> <last>Jung</last> </name> • <xsl: template match=“name”> <xsl: copy>

Cont. n 예제 • <name> <first>YS</first> <last>Jung</last> </name> • <xsl: template match=“name”> <xsl: copy> <xsl: value-of select = “. ”/> </xsl: copy> </xsl: template> n 결과 • <name> YS Jung </name> xml programming 90

<xsl: sort> n 자식 엘레먼트를 정렬할 수 있는 기능 제공 n <xsl: sort select=“Xpath

<xsl: sort> n 자식 엘레먼트를 정렬할 수 있는 기능 제공 n <xsl: sort select=“Xpath expression” lang=“lang” data-type=“text or number” order=“ascending or descending” case-order=“upper-first or lower-first”/> xml programming 91

모드(mode) n <xsl: template> <xsl: apply-templates> n 템플리트를 만들때, mode 속성을 지정하고 이름을 준다.

모드(mode) n <xsl: template> <xsl: apply-templates> n 템플리트를 만들때, mode 속성을 지정하고 이름을 준다. n • <xsl: template match=“name” mode=“TOC”/> • <xsl: template match=“name” mode=“body”/> n 이 템플리트를 호출할 때는 mode를 지정할 수 있다. • <xsl: apply-templates select=“name” mode=“TOC”/> xml programming 93

Cont. <? xml version="1. 0"? > <XSL> <title>XSLT - The Gory Details</title> <section>Templates <paragraph>

Cont. <? xml version="1. 0"? > <XSL> <title>XSLT - The Gory Details</title> <section>Templates <paragraph> We have been introduced briefly to the concept of <important>templates</important>. These are really the heart and soul of XSLT. Style sheets are simply a collection of these templates, which are applied to the input document to create the output document. </paragraph> <paragraph> Let's take another look at a previous. . . </paragraph> </section> <section> XSLT's Order of Operations <paragraph> If a style sheet can have. . . </paragraph> <paragraph>Actually. . . </paragraph> </section> </XSL> xml programming 94

Cont. xml programming 95

Cont. xml programming 95

<xsl: variable> n 상수정의 • <xsl: variable name=“PI”>3. 14</xsl: variable> • <xsl: variable name=“name”

<xsl: variable> n 상수정의 • <xsl: variable name=“PI”>3. 14</xsl: variable> • <xsl: variable name=“name” select=“/people/name”/> • 이경우에는 Content를 가질 수 없다. n 사용예 • <math pi=“{$PI}”/> • <xsl: value-of select=“$PI”/> • $를 붙여서 사용한다. 그러면 Xpath를 사용하는 어느곳에서든지 상수를 사용할 수 있다. xml programming 97

Cont. n 확장된 사용예 • <xsl: variable name=“space”> <xsl: text> </xsl: variable> <xsl: variable

Cont. n 확장된 사용예 • <xsl: variable name=“space”> <xsl: text> </xsl: variable> <xsl: variable name=“name”> <name> <xsl: value-of select=“/name/first”/> <xsl: value-of select=“$space”/> <xsl: value-of select=“/name/last”/> </name> </xsl: variable> <xsl: copy-of select=“$name”/> n 실습하기!!! xml programming 98

Cont. n 상수의 유효 영역(scope) n 예제 • <xsl: stylesheet version=“ 1. 0” xmlns:

Cont. n 상수의 유효 영역(scope) n 예제 • <xsl: stylesheet version=“ 1. 0” xmlns: xsl=“…”> <xsl: output method=“text”/> 전역 상수 <xsl: variable name=“age”>29</xsl: variable> <xsl: template match=“/”> <xsl: variable name=“name”>YS</xsl: variable> <xsl: value-of select=“concat($name, ‘ is ‘, $age)”/> <xsl: template> 지역 상수 </xsl: stylesheet> n 실행결과 • YS is 29 xml programming 99

Cont. n 예제 • <xsl: stylesheet version=“ 1. 0” xmlns: xsl=“…”> <xsl: output method=“text”/>

Cont. n 예제 • <xsl: stylesheet version=“ 1. 0” xmlns: xsl=“…”> <xsl: output method=“text”/> <xsl: variable name=“name”>YS</xsl: variable> <xsl: template match=“/”> <xsl: variable name=“name”>DJ</xsl: variable> <xsl: value-of select=“$name”/> </xsl: template> </xsl: stylesheet> n 결과 • DJ xml programming 100

Named Templates n Xpath에 일치되는 템플리트가 호출되는 것이 아니라 이름을 가지고 지정한 템 플리트가

Named Templates n Xpath에 일치되는 템플리트가 호출되는 것이 아니라 이름을 가지고 지정한 템 플리트가 호출되게 하는 방법이다. n 예제 • <xsl: template match=“/”> <xsl: for-each select=“name”> <xsl: call-template name=“bold”/> </xsl: for-each> Named Template를 호출한다. <xsl: for-each select=“not-name”> <xsl: call-template name=“bold”/> </xsl: for-each> </xsl: template> <xsl: template name=“bold”> <B><xsl: value-of select=“. ”/></B> </xsl: template> n 템플리트에서 name과 match를 동시에 사용할 수 있다. xml programming 101

Parameter n 비교 n <xsl: template name=“name”> First Name : <xsl: value-of select=“first”/> Last

Parameter n 비교 n <xsl: template name=“name”> First Name : <xsl: value-of select=“first”/> Last Name : <xsl: value-of select=“last”/> </xsl: template> n <xsl: template name=“name”> <xsl: param name=“first”><xsl: value-of select=“first”/></xsl: param> <xsl: param name=“last”><xsl: value-of select=“last”/></xsl: param> First Name : <xsl: value-of select=“$first”/> Last Name : <xsl: value-of select=“$last”/> </xsl: template> xml programming 102

Cont. n <xsl: template match="/"> <xsl: for-each select="name"> <!--여기가 새로운 부분 시작--> <xsl: call-template

Cont. n <xsl: template match="/"> <xsl: for-each select="name"> <!--여기가 새로운 부분 시작--> <xsl: call-template name="name"> <xsl: with-param name="first"><xsl: value-of select="given"/></xsl: with-param> <xsl: with-param name="last"><xsl: value-of select="family"/></xsl: with-param> </xsl: call-template> <!--여기가 새로운 부분 마지막--> </xsl: for-each> Param보다 with-param이 우선순위가 높다. </xsl: template> <xsl: template name=“name”> <xsl: param name=“first”><xsl: value-of select=“first”/></xsl: param> <xsl: param name=“last”><xsl: value-of select=“last”/></xsl: param> First Name : <xsl: value-of select=“$first”/> Last Name : <xsl: value-of select=“$last”/> </xsl: template> xml programming 103