使用XSLT删除xml文件中的DTD和XMNS [英] Remove DTD and XMNS in xml file using XSLT

查看:121
本文介绍了使用XSLT删除xml文件中的DTD和XMNS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我想使用xslt的xml文件中的DTD和XMLNS。



XMl文件:

<?xml version =" 1.0" encoding =" utf-8"?>

<!DOCTYPE Report SYSTEM" https://test.com/test/reports/dtd/tdr_1_11.dtd">

<报告名称="交易明细"
$
        Version =" 1.11"

        xmlns =" https://test.com/test/reports/dtd/tdr_1_11.dtd"

        AccountID =" testaccount"

        ReportStartDate =" 2012-11-21T07:00:00"

        ReportEndDate =" 2012-11-22T07:00:00">

    <请求>

    < / Requests>

< / Report>



$
结果:

$


<?xml version =" 1.0" encoding =" utf-8"?>

<报告名称="交易详情"

        ; Version =" 1.11"

        AccountID =" testaccount"

        ReportStartDate =" 2012-11-21T07:00:00"

        ReportEndDate =" 2012-11-22T07:00:00">

    <请求>

    < / Requests>

< / Report>



您能否分享上面的xslt。?

Hi,

I want to DTD and XMLNS in xml file useing xslt.

XMl Document:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE Report SYSTEM "https://test.com/test/reports/dtd/tdr_1_11.dtd">
<Report Name="Transaction Detail"
        Version="1.11"
        xmlns="https://test.com/test/reports/dtd/tdr_1_11.dtd"
        AccountID="testaccount"
        ReportStartDate="2012-11-21T07:00:00"
        ReportEndDate="2012-11-22T07:00:00">
    <Requests>
    </Requests>
</Report>


Result:


<?xml version="1.0" encoding="utf-8"?>
<Report Name="Transaction Detail"
        Version="1.11"
        AccountID="testaccount"
        ReportStartDate="2012-11-21T07:00:00"
        ReportEndDate="2012-11-22T07:00:00">
    <Requests>
    </Requests>
</Report>

Can you please share the xslt for the above one.?

推荐答案

XSLT数据模型不包含DTD,因此无论如何都会被XSLT处理丢弃。至于命名空间,它应该足以使用三个模板

The XSLT data model does not include a DTD so that would be dropped anyway by XSLT processing. As for the namespace it should suffice to use three templates

<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">

<xsl:template match="*">
  <xsl:element name="{local-name()}">
    <xsl:apply-templates select="@* | node()"/>
  </xsl:element>
</xsl:template>

<xsl:template match="@*">
  <xsl:attribute name="{local-name()}">
    <xsl:value-of select="."/>
  </xsl:attribute>
</xsl:template>

<xsl:template match="text() | comment() | processing-instruction()">
  <xsl:copy/>
</xsl:template>

</xsl:stylesheet>

请注意,同时使用.NET中的默认XML解析与MSXML 6一样,需要明确允许或忽略DTD处理,因此根据您的XSLT处理器和XML解析器处理您使用引用的DTD发布的文档,您需要
来启用DTD处理,例如使用.NET by将
XmlReaderSettings.DtdProcessing
设置为忽略或解析。

Note that with both the default XML parsing in .NET as well as with MSXML 6 DTD processing needs to be explicitly allowed or ignored so depending on your XSLT processor and XML parser to process a document liked you posted with a DTD referenced you need to enable DTD processing, for instance with .NET by setting XmlReaderSettings.DtdProcessing to Ignore or Parse.


这篇关于使用XSLT删除xml文件中的DTD和XMNS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆