
XSLTProcessor의 transformToXml 메서드는 XSLT 스타일 시트를 사용하여 XML 문서를 변환하는 메서드입니다. 이 메서드는 XSLT 스타일 시트를 적용하여 XML 문서를 변환한 결과를 XML 문자열로 반환합니다.
transformToXml 메서드의 사용 예제는 다음과 같습니다.
#hostingforum.kr
php
$xslt = new XSLTProcessor();
$xslt->importStyleSheet($xsl);
$xml = new DOMDocument();
$xml->loadXML($xmlString);
$transformedXml = $xslt->transformToXml($xml);
echo $transformedXml;
이 예제에서는 XSLT 스타일 시트를 적용하여 XML 문서를 변환한 결과를 XML 문자열로 반환합니다.
transformToXml 메서드는 다음과 같은 예외를 발생시킬 수 있습니다.
- XSLT 스타일 시트가 유효하지 않으면 XSLTProcessorException이 발생합니다.
- XML 문서가 유효하지 않으면 DOMException이 발생합니다.
이러한 예외를 처리하기 위해 try-catch 블록을 사용할 수 있습니다.
#hostingforum.kr
php
try {
$transformedXml = $xslt->transformToXml($xml);
echo $transformedXml;
} catch (XSLTProcessorException $e) {
echo "XSLT 스타일 시트가 유효하지 않습니다.";
} catch (DOMException $e) {
echo "XML 문서가 유효하지 않습니다.";
}
이 예제에서는 XSLT 스타일 시트가 유효하지 않거나 XML 문서가 유효하지 않은 경우 예외를 처리합니다.
2025-05-11 21:44