실행 시간에 소스 분석기 사용
실행 파일을 실행할 때 소스 분석기를 지정하면 해당 시점에 참조되는 URI를 해석하는 방법을 프로세서에 알릴 수 있습니다.
프로시저
실행 파일을 실행하는 시점에 소스 분석기를 지정하십시오.
그러면 예를 들어, fn:doc() 또는 document() 함수에 대한 호출에서 해당 시점에 참조되는 URI를 해석하는 방법을 프로세스에 알립니다.
기본 소스-분석 동작은 기본 URI가 사용 가능한 경우 표현식, 조회 또는 스타일시트 관점에서 상대적 URI를 해석하거나 기본 URI가 사용 불가능한 경우 현재 작업 디렉토리에 상대적인 파일 경로로 해석하는 것입니다. 절대적 URI는 그대로 사용됩니다.
이 동작을 변경하려면 XSourceResolver 인터페이스를 구현하는 Java™ 클래스를 작성하고 표현식, 조회 또는 스타일시트를 실행하기 전에 XDynamicContext에 등록하십시오.
다음은 소스 분석기를 등록하는 방법에 대한 기본 예제입니다.
XFactory factory = XFactory.newInstance();
XStaticContext staticContext = factory.newStaticContext();
// Prepare the stylesheet
XSLTExecutable executable = factory.prepareXSLT(new StreamSource(stylesheetFile), staticContext);
XDynamicContext dynamicContext = factory.newDynamicContext();
// Register the source resolver with the dynamic context
XSourceResolver sourceResolver=new ASourceResolver(replacementBase);
dynamicContext.setSourceResolver(sourceResolver);
// Execute the XPath expression
XSequenceCursor cursor = executable.execute(new StreamSource(inputFile), dynamicContext);