다음과 같은 매우 큰 xml 문서가 있습니다. 다음 발췌 내용과 같습니다. 웹에서 찾은 몇 가지 예제를 사용하여 파일을 여러 HTML 파일로 분할 할 수 있습니다.xslt를 사용하여 xml을 여러 HTML 파일로 분할
결과 파일의 유일한 문제점은 <h1>
태그와 다음 요소 앞에 모든 요소를 포함하고 다음 요소가있는 다음 <h1>
등을 가져야한다는 것입니다. 다음 H1 태그에 포함되지 않습니다 전에 그러니까 기본적으로 내가 필요한
<p>
,
<ol>
<pre>
) 다음과 같은 요소와 함께
<h1 id=h1>
에 대한 파일은 다음과 같은 요소를 만들어 현재 을 파일을 생성 할 수있다 생성 된 문서 그리고 나는 그것을하기 위해 xslt를 조절하는 방법을 모른다. 여기에 IBM 개발자 웹 사이트에서 다음 예제 원본 XML
<?xml version="1.0" encoding="UTF-8"?>
<paragraphs>
<h1 id= "h1">Header One</h1>
<p>The quick brown fox jumps over the lazy dog. </p>
<p>The quick brown fox jumps over the lazy dog. </p>
<p>The quick brown fox jumps over the lazy dog.</p>
<ol>
<li>
List 1
</li>
<li>
List 2
</li>
</ol>
<h1 id= "h2">Header Two</h1>
<p>The quick brown fox jumps over the lazy dog. </p>
<p>The quick brown fox jumps over the lazy dog.</p>
<ul>
<li>
List 3
</li
>
<li>
List 4
</li>
</ul>
<p>The quick brown fox jumps over the lazy dog.</p>
<h1 id= "h3">Header Three</h1>
<pre>my example one</pre>
<p>The quick brown fox jumps over the lazy dog.</p>
<pre> Another example</pre>
</paragraphs>
XSLT를 :
<html>
<body>Header One</body>
</html>
<html>
<body>Header Two</body>
</html>
:
http://www.ibm.com/developerworks/library/x-tipmultxsl/
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:output method="text"/>
<xsl:output method="html" indent="yes" name="html"/>
<xsl:template match="/">
<xsl:for-each select="//h1">
<xsl:variable name="filename"
select="concat('output/',@id,'.html')" />
<xsl:value-of select="$filename" /> <!-- Creating -->
<xsl:result-document href="{$filename}" format="html">
<html><body>
<xsl:value-of select="text()"/>
</body></html>
</xsl:result-document>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
결과 파일은 다음과 같이
개
<html>
<body>Header Three</body>
</html>
고마워요. 난 당신이 이런 식으로 뭔가를 찾고 생각
을, 나와 함께 곰하시기 바랍니다. – ManUO