简体   繁体   English

如何在XSLT上生成doctype XML文件

[英]How to generate doctype XML file on XSLT

I need to convert XML format into doctype XML format with the help of XSLT FILE. 我需要借助XSLT FILE将XML格式转换为doctype XML格式。 Source file is normal XML. 源文件是常规XML。

As per my targeted file I need to get: 根据我的目标文件,我需要获得:

<!DOCTYPE Pip3B3ShipmentStatusNotification SYSTEM "3B3_MS_R01_00_ShipmentStatusNotification.dtd">

My xslt code is given below 我的xslt代码如下

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:transform version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output doctype-system="3B3_MS_R01_00_ShipmentStatusNotification.dtd" encoding="UTF-8"  indent="yes"/>
    <xsl:template match="/">
        <Pip3B3ShipmentStatusNotification>
            <fromRole>
                <PartnerRoleDescription>
                    <ContactInformation>
                        <contactName>
                        </contactName>
                    </ContactInformation>
                </PartnerRoleDescription>
            </fromRole>
        </Pip3B3ShipmentStatusNotification>
    </xsl:template>
</xsl:transform>

My macro given below, please check macro and let me know if it have any issue 我的宏在下面给出,请检查宏,让我知道是否有任何问题

Sub dummy()

    Call Transform("C:\Users\nypaul\Desktop\yves\out\source.xml", "C:\Users\nypaul\Desktop\yves\out\template\template.xsl", "C:\Users\nypaul\Desktop\yves\out\output.xml")

    MsgBox "ok"

End Sub

Function Transform(sourceFile, styleSheetFile, resultFile) As Boolean

    Dim Source As Object
    Dim StyleSheet As Object
    Dim Result As Object

    Set Source = CreateObject("MSXML2.DOMDocument")
    Set StyleSheet = CreateObject("MSXML2.DOMDocument")
    Set Result = CreateObject("MSXML2.DOMDocument")

    On Error GoTo TheEnd

    Transform = True
    Source.async = False
    Source.Load sourceFile

    StyleSheet.async = False
    StyleSheet.Load styleSheetFile
    Source.transformNodeToObject StyleSheet, Result
    Result.Save resultFile
    Exit Function

TheEnd:
    Transform = False

End Function

How can I understand what is the error? 我如何理解错误所在?

The problem is that when you do 问题是当你这样做

Source.transformNodeToObject StyleSheet, Result
Result.Save resultFile

the serialization of the result tree is being done by the Result.Save operation, not by the XSLT transformation, and therefore it is being done without any knowledge of the xsl:output declaration. 结果树的序列化是通过Result.Save操作完成的,而不是通过XSLT转换完成的,因此,在不了解xsl:output声明的情况下进行了结果树的序列化。 This is because Result is a DOM Document object, so the XSLT processor merely creates a DOM, which does not involve serialization. 这是因为Result是一个DOM Document对象,因此XSLT处理器仅创建一个DOM,而不涉及序列化。

I'm not an expert in this particular transformation API but I think if you supply a Stream as the second argument of transformNodeToObject then it should work. 我不是这个特定转换API的专家,但是我认为,如果您提供Stream作为transformNodeToObject的第二个参数,那么它应该可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM