<xsl:processing-instruction> 요소
출력에 처리 명령 노드를 생성합니다.
<xsl:processing-instruction
name = "pi-name">
</xsl: processing-instruction>
특성
- name
필수 요소. 처리 명령의 NCName입니다.
요소 정보
발생 횟수 |
제한 없음 |
부모 요소 |
xsl:attribute, xsl:comment, xsl:copy, xsl:element, xsl:fallback, xsl:for-each, xsl:if, xsl:message, xsl:otherwise, xsl:param, xsl:processing-instruction, xsl:template, xsl:variable, xsl:when, xsl:with-param, 출력 요소 |
자식 요소 |
xsl:apply-imports, xsl:apply-templates, xsl:call-template, xsl:choose, xsl:copy, xsl:copy-of, xsl:fallback, xsl:for-each, xsl:if, xsl:message, xsl:number, xsl:text, xsl:value-of, xsl:variable |
설명
<xsl:processing-instruction> 요소는 출력에 처리 명령 노드를 생성합니다. 이름은 name 특성으로 표시합니다. 요소의 내용은 나머지 처리 명령을 제공합니다.
XML 선언은 처리 명령이 아니며 <xsl:output> 요소에서 특성을 설정하여 생성해야 합니다.
예제
다음 예제에서는 XML 선언을 생성하는 템플릿과 출력에서 명령을 처리하는 스타일시트를 보여 줍니다.
XML 파일(customers.xml)
<?xml version='1.0'?>
<?xml-stylesheet type="text/xsl" href="pi.xsl" ?>
<customers>
<customer>
<name>James Smith</name>
<address>123 Elm St.</address>
<phone>(123) 456-7890</phone>
</customer>
<customer>
<name>Amy Jones</name>
<address>456 Oak Ave.</address>
<phone>(156) 789-0123</phone>
</customer>
</customers>
XSLT 파일(pi.xsl)
<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output method='xml' version='1.0'/>
<xsl:template match="/">
<xsl:processing-instruction name="xml-stylesheet">
<xsl:text>type="text/xsl" href="style.xsl"</xsl:text>
</xsl:processing-instruction>
<xsl:apply-templates />
</xsl:template>
<xsl:template match="@* | *">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template></xsl:stylesheet>
실습
위의 코드를 복사하고 로컬 드라이브의 적절한 파일에 저장합니다.
다음과 같이 명령 프롬프트에서 msxsl.exe 유틸리티를 사용하여 www.microsoft.com/downloads/에 있는 예제를 실행합니다.
msxsl customers.xml pi.xsl -o new-cust.xml
출력
이 변환 결과는 여기에 포함된 새 스타일시트와 동일한 XML 파일입니다. 출력 파일인 new-cust.xml의 모양은 다음과 같습니다.
<?xml version="1.0" encoding="UTF-16"?>
<?xml-stylesheet type="text/xsl" href="style.xsl" ?>
<customers>
<customer>
<name>James Smith</name>
<address>123 Elm St.</address>
<phone>(123) 456-7890</phone>
</customer>
<customer>
<name>Amy Jones</name>
<address>456 Oak Ave.</address>
<phone>(156) 789-0123</phone>
</customer>
</customers>