Wie kann ich eine formatierte XML-Quelle in WORD-Dokumente einbetten?

7288
eckes

Ich schreibe eine Dokumentation mit WORD, die als Beispiel XML-Quellcode (ganze Dateien) enthält. Die Art und Weise, wie ich das derzeitige XML einbettet, ist ziemlich umständlich und erscheint mir nicht wirklich wartungsfähig:

  • Ich beende die Bearbeitung des Dokuments in WORD und erstelle daraus eine PDF-Datei mit Acrobat
  • Als nächstes öffne ich meine XML-Dateien (2x Eingabedateien, 2x generierte Ausgabedateien) mit IE und drucke sie mit dem von Acrobat gelieferten PDF-Drucker
  • Jetzt öffne ich Acrobat Pro und füge die vier XML-PDF-Dateien meinem Originaldokument hinzu

Das Problem bei diesem Arbeitsablauf ist für mich, dass zu viel manuelle Arbeit erforderlich ist, um die Dokumentation fertigzustellen.

Was ich bisher ausprobiert habe, ist für mich nicht wirklich befriedigend:

  • Konvertieren von XML in PDF und Anhängen wie oben beschrieben
  • Öffnen Sie die XML-Dateien mit SCiTE, kopieren Sie sie als RTF und fügen Sie sie in Word ein
  • Ich habe mit den LaTeX-Paketen herumgepfiffen, pygments und Listings herumgespielt (ich könnte auch die Dokumente mit LaTeX schreiben), fand jedoch in jedem dieser Pakete einige unlösbare Probleme

Ich suche nach einem Weg, um meine Dokumentation automatischer zu gestalten . Zum Beispiel das Einbetten der XML-Dateien einschließlich der Formatierung des IE (die ich ziemlich lesbar finde). Die Dateien sollten per Referenz eingefügt werden, damit ich die XML-Quellen nicht jedes Mal manuell einfügen muss, wenn sich die XML-Änderungen ändern.


Edit:
Mit der exzellenten Antwort von Jeremy konnte ich endlich ein XSLT einrichten, das eine bestimmte XML-Datei in schönes HTML umwandelt. Mein XSLT basiert auf dem ursprünglichen IE-Stylesheet, weist jedoch geringfügige Änderungen auf, da Word die Ausführung dynamischer Elemente, die im IE-Stylesheet erforderlich sind, nicht zulässt.

In diesem Zusammenhang habe ich den IE XSLT ( hier gefunden ) so geändert, dass er kein Skript mehr benötigt (was in meinem Fall absolut nicht benötigt wird). Zur Dokumentation: Hier ist das Stylesheet:

<?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  <!-- tag --> .t  <!-- attribute names --> .an  <!-- tag in xsl namespace --> .xt  <!-- attribute in xml or xmlns namespace --> .ns  <!-- attribute in dt namespace --> .dt  <!-- markup characters --> .m  <!-- text node --> .tx  <!-- single-line (inline) cdata --> .di {} <!-- DOCTYPE declaration --> .d  <!-- pi --> .pi  <!-- single-line (inline) comment --> .ci  </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> 
3

1 Antwort auf die Frage

3
Jeremy W

Sie können dies tun, indem Sie ein INCLUDETEXT-Feld in Ihr Word-Dokument einfügen


  • Beziehen oder erstellen Sie eine XSL-Transformation, die gültiges WordPressingML (Word 2003, 2007) ausgibt. Ich habe einen gefunden, der aussieht, als könnte er hier von IE verwendet werdenC:\Windows\SysWOW64\wbem\en-US\xml.xsl

  • Fügen Sie das INCLUDETEXT-Feld wie folgt ein:

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

Wenn sich Ihre XML-Quelldatei ändert, müssen Sie jedes INCLUDETEXT-Feld aktualisieren (hervorheben und drücken F3) oder VBA hinzufügen, um die Felder zu aktualisieren, wenn das Dokument geladen wird.

+1 das ist großartig! irgendwelche Hinweise, wie man die Einrückungen richtig macht? eckes vor 11 Jahren 0
Diese [Anleitung zum Erstellen eines Xslt-Xslt-Generic für XML-Quellcode] (http://www.xml.com/lpt/a/1681) ist hilfreich. Am Ende gibt es eine komplette XSL-Datei. Jeremy W vor 11 Jahren 0
umso geiler! die Kopfprämie soll dir gehören! eckes vor 11 Jahren 0