1
나는 자바 예제 응용 프로그램에 this 예를 재현하려면 :XSLT로 작업하기. 샘플 응용 프로그램
http://www.w3schools.com/Xsl/tryxslt.asp?xmlfile=cdcatalog&xsltfile=cdcatalog
이 내 샘플 응용 프로그램입니다 :
input.xml
이 - W3 스쿨 사이트transform.xslt
에 표시 한 내용이 포함은 - w3schools 사이트에 표시된 콘텐츠가 포함되어 있습니다.output.xml
- 단지 빈 파일입니다. 내용으로 xslt 변환 결과로 채워집니다.
모든 파일은 내 /myproject/...resource/myclasspath
디렉토리에 있습니다. 나는이 응용 프로그램을 시작하면, 그것은 여전히 output.xml
의 모든 내용이없는
public class TestMain {
public static void main(String[] args) throws IOException, URISyntaxException, TransformerException {
TransformerFactory factory = TransformerFactory.newInstance();
InputStream xstlStream = TestMain.class.getResourceAsStream("transform.xslt");
Source xslt = new StreamSource(xstlStream);
Transformer transformer = factory.newTransformer(xslt);
InputStream inputStream = TestMain.class.getResourceAsStream("input.xml");
Source inputSource = new StreamSource(inputStream);
URL url = TestMain.class.getResource("output.xml");
transformer.transform(inputSource, new StreamResult(new File(url.toURI())));
}
}
: 는, 그것이 여기에 샘플 응용 프로그램을)
[나는 getResourceAsStream
을 사용]. 나는 w3schools 사이트에 표시된 것과 동일한 결과를 예외로 사용했습니다.
기본적으로 특정 경우에 대해 <data></data>
태그에 속성을 추가하여 <data attr=""></data>
과 같은 결과를 얻으 려합니다. 먼저이 샘플 앱부터 시작하십시오.
Q : 왜 작동하지 않습니까?
오 .. 하느님. 알았다. 매번 내가 그것을 게시 할 때마다. 내 소스 파일에서 직접 출력을 찾고 있었지만 컴파일 된 출력에서는 그렇지 않았습니다. 희망이 사람에게 도움이 될 것입니다. – ses
확인. 마지막 질문에 대한 대답은 다음과 같습니다. http://stackoverflow.com/questions/2972992/xslt-how-to-add-attributes-to-copy-of – ses
솔루션을 답변으로 추가하고 동의하여 사람들 이 질문에 답을 얻었습니다. – JLRishe