기본 XSLT 조작 수행

XSLT 변환을 수행하기 위해 XFactory.prepareXSLT 메소드를 사용하여 작성된 XSLTExecutable 인스턴스를 사용할 수 있습니다.

이 태스크 정보

XSLT 스타일시트는 JAXP 소스 오브젝트를 사용하는 XFactory.prepareXSLT 메소드로 전달할 수 있습니다. 결과로 생성된 XSLTExecutable 인스턴스는 스레드 보안 처리되며, 이를 재사용하여 여러 입력 문서를 변환할 수 있습니다.

프로시저

다음은 해석된 변환을 준비 및 실행하는 기본 예제입니다.
// Create the factory
XFactory factory = XFactory.newInstance();

// Create a StreamSource for the stylesheet
StreamSource stylesheet = new StreamSource("simple.xsl");

// Create an XSLT executable for the stylesheet
XSLTExecutable executable = factory.prepareXSLT(stylesheet);

// Create the input source
Source input = new StreamSource("simple.xml");

// Create the result
Result result = new StreamResult(System.out);

// Execute the transformation
executable.execute(input, result);
다음은 컴파일된 변환을 준비 및 실행하는 기본 예제입니다.
// Create the factory
XFactory factory = XFactory.newInstance();

// Create a StreamSource for the stylesheet
StreamSource stylesheet = new StreamSource("simple.xsl");

// Create a new static context
XStaticContext staticContext = factory.newStaticContext();

// Enable the compiler
staticContext.setUseCompiler(true);

// Create an XSLT executable for the stylesheet
XSLTExecutable executable = factory.prepareXSLT(stylesheet, staticContext);

// Create the input source
Source input = new StreamSource("simple.xml");

// Create the result
Result result = new StreamResult(System.out);

// Execute the transformation
executable.execute(input, result);
다음은 ID 변환을 작성하는 기본 예제입니다.
// Create the factory
XFactory factory = XFactory.newInstance();
           
// Create the item factory
XItemFactory itemFactory = factory.getItemFactory();

// Create the input source
Source input = new StreamSource("simple.xml");
           
// Create the XItemView object from the input source
XItemView item = itemFactory.item(input);
           
// Create an XOutputParameters object
XOutputParameters params = factory.newOutputParameters();

// Set parameters
params.setMethod("xml");
params.setEncoding("UTF-8");
params.setIndent(true);
           
// Create the result
Result result = new StreamResult(System.out);
           
// Serialize to the result
item.exportItem(result, params);
다음은 스키마 인식 변환을 작성하는 기본 예제입니다.
// Create the factory
XFactory factory = XFactory.newInstance();

// Enable validation
factory.setValidating(true);

// Create the schema source
StreamSource schema = new StreamSource("schema.xsd");

// Register the schema
factory.registerSchema(schema);

// Create the stylesheet source
StreamSource stylesheet = new StreamSource("schema.xsl");

// Create an XSLT executable for the stylesheet
XSLTExecutable executable = factory.prepareXSLT(stylesheet);

// Create the input source
StreamSource input = new StreamSource("schema.xml");

// Create the result
StreamResult result = new StreamResult(System.out);

// Execute the transformation
executable.execute(input, result);

주제 유형을 표시하는 아이콘 태스크 주제



시간소인 아이콘 마지막 업데이트 날짜: last_date
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=txml_ops_xslt
파일 이름:txml_ops_xslt.html