WORD 문서에 서식이 지정된 XML 소스를 어떻게 삽입할 수 있나요?

WORD 문서에 서식이 지정된 XML 소스를 어떻게 삽입할 수 있나요?

저는 XML 소스 코드(전체 파일)를 예로 포함하는 WORD를 사용하여 문서를 작성하고 있습니다. 현재 XML을 삽입하는 방식은 매우 번거롭고 유지관리가 쉽지 않은 것 같습니다.

  • WORD에서 문서 편집을 마치고 Acrobat을 사용하여 PDF를 만들고 있습니다.
  • 다음으로 IE를 사용하여 XML 파일(2x 입력 파일, 2x 생성된 출력 파일)을 열고 Acrobat에서 제공하는 PDF 프린터로 인쇄합니다.
  • 이제 Acrobat Pro를 열고 4개의 XML-PDF 파일을 원본 문서에 첨부합니다.

저에게 있어 해당 작업 흐름의 문제는 문서화를 완료하는 데 너무 많은 수작업이 필요하다는 것입니다.

내가 지금까지 시도한 것은 실제로 만족스럽지 않습니다.

  • 위에서 설명한 대로 각 XML을 PDF로 변환하고 추가합니다.
  • XML 파일 열기SCiTE, RTF로 복사하여 Word에 붙여넣기
  • 생성된 LaTeX 패키지, pygments 및 목록을 가지고 놀았지만(LaTeX로도 문서를 작성할 수 있었습니다) 몇 가지를 발견했습니다.해결 불가능한 문제이 각 패키지에는

문서를 생성하는 방법을 찾고 있습니다.더욱 자동적인. 예를 들어 IE의 형식을 포함하는 XML 파일을 포함합니다(매우 읽기 쉽습니다). XML이 변경될 때마다 XML 소스를 수동으로 붙여넣을 필요가 없도록 파일을 참조로 포함해야 합니다.


편집하다:
우수한 것을 사용하여답변주어진제레미, 마침내 주어진 XML 파일을 멋진 HTML로 변환하는 XSLT를 설정할 수 있었습니다. 내 XSLT는 원본 IE 스타일시트를 기반으로 하지만 Word가 IE 스타일시트에 필요한 동적 항목의 실행을 거부하므로 약간 수정되었습니다.

이에 대해 IE XSLT(여기에서 발견) 더 이상 스크립팅이 필요하지 않도록 합니다(제 경우에는 전혀 필요하지 않습니다). 문서화: 스타일시트는 다음과 같습니다.

<?xml version="1.0"?>
<!--
  IE5 default style sheet, provides a view of any XML document
  and provides the following features:
  - color coding of markup
  - color coding of recognized namespaces - xml, xmlns, xsl, dt

  This style sheet is available in IE5 in a compact form at the URL
  "res://msxml.dll/DEFAULTSS.xsl".  This version differs only in the
  addition of comments and whitespace for readability.

  Author:  Jonathan Marsh ()
  Modified:   05/21/2001 by Nate Austin ()
                         Converted to use XSLT rather than WD-xsl
-->

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dt="urn:schemas-microsoft-com:datatypes" xmlns:d2="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882">
  <xsl:strip-space elements="*"/>
  <xsl:output method="html"/>
  <xsl:template match="/">
    <HTML>
      <HEAD>
        <STYLE>
          BODY {font:x-small 'Courier New'; margin-right:1.5em}
          <!-- tag -->
          .t  {color:#990000}
          <!-- attribute names -->
          .an {color:#990000;}
          <!-- tag in xsl namespace -->
          .xt {color:#990099}
          <!-- attribute in xml or xmlns namespace -->
          .ns {color:red}
          <!-- attribute in dt namespace -->
          .dt {color:green}
          <!-- markup characters -->
          .m  {color:blue}
          <!-- text node -->
          .tx {font-weight:bold}
          <!-- single-line (inline) cdata -->
          .di {}
          <!-- DOCTYPE declaration -->
          .d  {color:blue}
          <!-- pi -->
          .pi {color:blue}
          <!-- single-line (inline) comment -->
          .ci {color:#888888}
        </STYLE>
      </HEAD>
      <BODY class="st">
        <xsl:apply-templates>
          <xsl:with-param name="depth">0</xsl:with-param>
        </xsl:apply-templates>
      </BODY>
    </HTML>
  </xsl:template>

  <!-- decides whether we have a tag in an xsl namespace or a regular tag -->
  <xsl:template name="classwriter">
    <xsl:param name="curname"/>
    <SPAN>
      <xsl:attribute name="class"><xsl:if test="starts-with($curname,'xsl:')">x</xsl:if>t</xsl:attribute>
      <xsl:value-of select="$curname"/>
    </SPAN>
  </xsl:template>

  <!-- Helper that does the indent -->
  <xsl:template name="indent">
    <xsl:param name="depth"/>
    <xsl:if test="$depth &gt; 0">
      <xsl:text>&#160;&#160;</xsl:text>
      <xsl:call-template name="indent">
        <xsl:with-param name="depth" select="$depth - 1"/>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>

  <!-- Template for pis not handled elsewhere -->
  <xsl:template match="processing-instruction()">
    <DIV class="e">
      <SPAN class="m">&lt;?</SPAN>
      <SPAN class="pi">
        <xsl:value-of select="name()"/>&#160;<xsl:value-of select="."/>
      </SPAN>
      <SPAN class="m">?&gt;</SPAN>
    </DIV>
  </xsl:template>

  <!-- Template for attributes not handled elsewhere -->
  <xsl:template match="@*">
    <SPAN class="an">&#160;<xsl:value-of select="name()"/></SPAN><SPAN class="m">="</SPAN><B><xsl:value-of select="."/></B><SPAN class="m">"</SPAN>
  </xsl:template>

  <!-- Template for text nodes -->
  <xsl:template match="text()">
    <DIV class="e">
      <SPAN class="tx">
        <xsl:value-of select="."/>
      </SPAN>
    </DIV>
  </xsl:template>


  <!-- Note that in the following templates for comments
and cdata, by default we apply a style appropriate for
single line content (e.g. non-expandable, single line
display).  But we also inject the attribute 'id="clean"' and
a script call 'f(clean)'.  As the output is read by the
browser, it executes the function immediately.  The function
checks to see if the comment or cdata has multi-line data,
in which case it changes the style to a expandable,
multi-line display.  Performing this switch in the DHTML
instead of from script in the XSL increases the performance
of the style sheet, especially in the browser's asynchronous
case -->

  <!-- Template for comment nodes -->
  <xsl:template match="comment()">
    <xsl:param name="depth"/>
    <DIV class="k">
      <SPAN>
        <SPAN class="m">
          <xsl:call-template name="indent">
            <xsl:with-param name="depth" select="$depth"/>
          </xsl:call-template>
          &lt;!--
        </SPAN>
      </SPAN>
      <SPAN class="ci">
        <xsl:value-of select="."/>
      </SPAN>
      <SPAN class="m">--&gt;</SPAN>
    </DIV>
  </xsl:template>

  <!-- Note the following templates for elements may
examine children.  This harms to some extent the ability to
process a document asynchronously - we can't process an
element until we have read and examined at least some of its
children.  Specifically, the first element child must be
read before any template can be chosen.  And any element
that does not have element children must be read completely
before the correct template can be chosen. This seems an
acceptable performance loss in the light of the formatting
possibilities available when examining children. -->

  <!-- Template for elements not handled elsewhere (leaf nodes) -->
  <xsl:template match="*">
    <xsl:param name="depth"/>
    <DIV class="e">
      <xsl:call-template name="indent">
        <xsl:with-param name="depth" select="$depth"/>
      </xsl:call-template>
      <SPAN class="m">&lt;</SPAN>
      <xsl:call-template name="classwriter"><xsl:with-param name="curname" select="name()"/></xsl:call-template>
      <xsl:apply-templates select="@*"/>
      <SPAN class="m"> /&gt;</SPAN>
    </DIV>
  </xsl:template>

  <!-- Template for elements with comment, pi and/or cdata children -->
  <xsl:template match="*[comment() | processing-instruction()]">
    <xsl:param name="depth"/>
    <DIV class="e">
      <SPAN class="m">&lt;</SPAN>
      <xsl:call-template name="classwriter"><xsl:with-param name="curname" select="name()"/></xsl:call-template>
      <xsl:apply-templates select="@*">
        <xsl:with-param name="depth" select="$depth + 1"/>
      </xsl:apply-templates>
      <SPAN class="m">&gt;</SPAN>
      <DIV>
        <xsl:apply-templates>
          <xsl:with-param name="depth" select="$depth + 1"/>
        </xsl:apply-templates>
        <DIV>
          <SPAN class="m">&lt;/</SPAN>
          <xsl:call-template name="classwriter"><xsl:with-param name="curname" select="name()"/></xsl:call-template>
          <SPAN class="m">&gt;</SPAN>
        </DIV>
      </DIV>
    </DIV>
  </xsl:template>

  <!-- Template for elements with only text children -->
  <xsl:template match="*[text() and not(comment() | processing-instruction())]">
    <xsl:param name="depth"/>
    <DIV class="e">
      <!-- write the starting tag -->
      <xsl:call-template name="indent">
        <xsl:with-param name="depth" select="$depth"/>
      </xsl:call-template>
      <SPAN class="m">&lt;</SPAN>
      <xsl:call-template name="classwriter"><xsl:with-param name="curname" select="name()"/></xsl:call-template>
      <xsl:apply-templates select="@*">
        <xsl:with-param name="depth" select="$depth + 1"/>
      </xsl:apply-templates>
      <SPAN class="m">&gt;</SPAN>
      <!-- write the tag content -->
      <SPAN class="tx">
        <xsl:value-of select="."/>
      </SPAN>
      <!-- write the end tag -->
      <SPAN class="m">&lt;/</SPAN>
      <xsl:call-template name="classwriter"><xsl:with-param name="curname" select="name()"/></xsl:call-template>
      <SPAN class="m">&gt;</SPAN>
    </DIV>
  </xsl:template>

  <!-- Template for elements with element children -->
  <xsl:template match="*[*]">
    <xsl:param name="depth"/>
    <DIV class="e">
      <xsl:call-template name="indent">
        <xsl:with-param name="depth" select="$depth"/>
      </xsl:call-template>
      <SPAN class="m">&lt;</SPAN>
      <xsl:call-template name="classwriter"><xsl:with-param name="curname" select="name()"/></xsl:call-template>
      <xsl:apply-templates select="@*" />
      <SPAN class="m">&gt;</SPAN>
      <DIV>
        <xsl:apply-templates>
          <xsl:with-param name="depth" select="$depth + 1"/>
        </xsl:apply-templates>
        <DIV>
          <xsl:call-template name="indent">
            <xsl:with-param name="depth" select="$depth"/>
          </xsl:call-template>
          <SPAN class="m">&lt;/</SPAN>
          <xsl:call-template name="classwriter"><xsl:with-param name="curname" select="name()"/></xsl:call-template>
          <SPAN class="m">&gt;</SPAN>
        </DIV>
      </DIV>
    </DIV>
  </xsl:template>

  <xsl:template match="text()" />
</xsl:stylesheet>

답변1

당신은 이것을 할 수 있습니다Word 문서에 INCLUDETEXT 필드 삽입


  • 유효한 WordPressingML(Word 2003, 2007)을 출력하는 XSL 변환을 얻거나 만듭니다. IE에서 사용할 수 있는 것 같은 것을 찾았습니다.C:\Windows\SysWOW64\wbem\en-US\xml.xsl

  • 다음과 같이 INCLUDETEXT 필드를 삽입합니다.

    { INCLUDETEXT "c:\\a\\myxml.xml" \t c:\\a\\myxml.xsl \c xml }

소스 XML 파일이 변경되면 각 INCLUDETEXT 필드를 업데이트하거나(강조 표시하고 키를 누름 F3) VBA를 추가하여 문서가 로드될 때 필드를 새로 고쳐야 합니다.

관련 정보