【问题标题】:using xslt to remove info path declarations form info path XML ? <? mso .......>使用 xslt 从信息路径 XML 中删除信息路径声明? <? mso ........>
【发布时间】:2013-06-27 14:28:50
【问题描述】:

使用 xslt 我能够删除命名空间,但如何删除 &lt;?mso...?&gt; 标记?

我正在尝试将信息路径 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>

【问题讨论】:

  • 如果你想使用身份转换模式来删除一些节点,那么你需要编写一个模板匹配那个空节点,所以你需要&lt;xsl:template match="processing-instruction()[starts-with(name(), 'mso-')]"/&gt;。如果我正确理解您的问题,您发布的样式表会复制处理指令,这不是您想要的。

标签: xml xslt ssis infopath


【解决方案1】:

节点的类型称为处理指令所以使用

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多