2013-06-17 3 views
0

몇 번의 시행 착오 끝에 내 자신의 질문을 해결했습니다. 도움을 주신 모든 분들께 감사드립니다.XSLT를 사용하여 폴더의 XML 파일을 XML 파일로 변환

로컬 시스템의 폴더에있는 일련의 XML 파일을 변환하는 방법에 대한 질문이 있습니다. 주제 텍스트()를 기반으로 원래 이름을 유지하면서 XML로 파일을 변환해야합니다.

현재 xslt를 사용하여 파일을 변환 할 수 있지만 원하는 결과를 얻을 수 있지만 파일 수가 많아 한 번에 하나씩 파일을 변환하는 것이 바람직하지 않습니다.

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE topic PUBLIC "-//OASIS//DTD DITA Topic//EN" "topic.dtd"> 
<topic> 
    <title class="- topic/title "> 
     Term 
    </title> 
    <body class="- topic/body "> 
     <p class="- topic/p ">Paragraph new</p> 
     <p class="- topic/p ">(See New parag.)</p> 
     <p class="- topic/p ">(See Next parag.)</p> 
     <p class="- topic/p ">(See Test.)</p> 
     <p class="- topic/p ">(See The other parag)</p> 
     <p class="- topic/p ">(Refer to the conclusion)</p> 
    </body> 
</topic> 

을 내 XSLT처럼 다음

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    version="2.0" 
    xmlns:ditaarch="http://dita.oasis-open.org/architecture/2005/" >  

    <!-- This adds DOCTYPE declaration --> 
    <xsl:output method="xml" encoding="UTF-8" 
     doctype-public="-//OASIS//DTD DITA Glossary//EN" 
     name="mygloss" doctype-system="glossary.dtd" omit-xml-declaration="no" indent="yes" /> 
    <xsl:output omit-xml-declaration="no" indent="yes"/> 
    <xsl:param name="files" select="collection('../A/?select=*.dita;recurse=yes')"/> 

    <xsl:template match="node()|@*"> 
     <xsl:copy copy-namespaces="no"> 
      <xsl:apply-templates select="node()|@*"/> 
     </xsl:copy> 
    </xsl:template> 

    <xsl:template match="/"> 

     <xsl:for-each select="$files//topic"> 
      <!--had issues with this portion, but fixed it by changing from topic/>text() to title/text(). --> 
      <xsl:result-document href="outputDITANEW/{title/text()}.dita" format="mygloss"> 

       <glossentry id="{concat('test', generate-id())}"> 
        <glossterm id="{concat('test_title', generate-id())}"> 
         <xsl:value-of select="title"/> 
        </glossterm> 
        <glossdef> 
         <xsl:for-each select="body"> 
          <xsl:apply-templates/> 
         </xsl:for-each> 
        </glossdef> 
       </glossentry> 
      </xsl:result-document> 
     </xsl:for-each> 

    </xsl:template> 
</xsl:stylesheet> 

출력 XML 보이는 것입니다 :

내 입력 XML은 다음과 같이 내가 XSLT를 사용하는 것을 시도했다

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE glossentry 
    PUBLIC "-//OASIS//DTD DITA Glossary//EN" "glossary.dtd"> 
<glossentry id="test_d2e11"> 
    <glossterm id="new_term_d2e3"> 
     Term 
    </glossterm> 
    <glossdef> 
     <p>Paragraph new</p> 
     <p>(See New parag.)</p> 
     <p>(See Next parag.)</p> 
     <p>(See Test.)</p> 
     <p>(See The other parag)</p> 
     <p>(Refer to the conclusion)</p> 
    </glossdef> 
</glossentry> 

collection() 및 result-document()를 사용하지만 작동하게 만들 수 없습니다.

위의 xslt는 다음과 같은 오류를 표시합니다. 두 개 이상의 항목 시퀀스가 ​​concat()의 첫 번째 인수로 허용되지 않습니다.

내 질문에 더 명확하게 전달되기를 바랍니다.

미리 도움을 주셔서 감사합니다.

+0

당신이 어떤 문제에 직면하고있다? –

+1

collection() 및 xsl : result-document를 사용하는 것이 올바른 방법입니다. 우리가 한 일과 실패한 행동에 대해 알려주십시오. 그러면 실수를 바로 잡는 데 도움을 줄 수 있습니다. –

+0

내 질문과 내가 다음과 같은 오류가 실행중인 문제를 업데이트했습니다 : 두 개 이상의 항목의 시퀀스를 concat() 첫 번째 인수로 사용할 수 없습니다. – ManUO

답변

0

몇 번의 시행 착오 끝에 내 자신의 질문을 해결했습니다. 도움을 주신 모든 분들께 감사드립니다.

주요 변화는 여기되었다 : 수집() 및 결과-문서를()를 사용할 때

<xsl:result-document href="outputDITANEW/{title/text()}.dita" format="mygloss"> 
관련 문제