2

<?mso...?>xslt を使用して名前空間を削除できましたが、タグを削除するにはどうすればよいですか?

情報パス 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>
4

1 に答える 1

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>
于 2013-06-27T14:44:30.473 に答える