使用xslt从信息路径XML中删除信息路径声明? <! - ? mso .......-->

时间:2013-06-27 14:28:51

标签: xml xslt ssis infopath

使用xslt我能够删除命名空间,但如何删除<?mso...?>标记?

我正在尝试将信息路径XML转换为XML并将其存储在数据库中。

  <?xml version="1.0"?>

    <?mso-infoPathSolution name="urn:schemas-microsoft-com:office:infopath:Zone-Zero-Observation-Card-with-form-audit-no-approval-mobile-view-Test-1:-myXSD-2012-09-05T20-51-15" solutionVersion="1.0.0.873" productVersion="14.0.0.0" PIVersion="1.0.0.0" href="test.xsn"?>
    <?mso-application progid="InfoPath.Document" versionProgid="InfoPath.Document.3"?>
    <?mso-infoPath-file-attachment-present?>

下面是我试过的xslt,但没有帮助。

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml"  indent="no"/>

  <xsl:template match="/|comment()|processing-instruction()[starts-with(name(), 'mso-')]">
    <xsl:copy>
      <xsl:apply-templates/>
    </xsl:copy>
  </xsl:template>

  <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:stylesheet>

1 个答案:

答案 0 :(得分:2)

节点类型称为处理指令,因此请使用

<xsl:template match="processing-instruction()[starts-with(name(), 'mso-')]"/>

与身份转换模板一起

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

这样,名称以mso-开头的处理指令将不会被复制。

我将展示一个完整的样式表:

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

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

  <xsl:template match="processing-instruction()[starts-with(name(), 'mso-')]"/>

  <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:stylesheet>
相关问题