-2

xml でノードをコピーできるようにする必要がありますが、データ自体はコピーできません。

例:

<Report>   
    <PaymentAccountInfo>     
        <AccountName>Demo Disbursement Account</AccountName>
    </PaymentAccountInfo>
</Report>    

これはちょうどする必要があります

<Report>
    <PaymentAccountInfo>
        <AcocuntName></AccountName>
    </PaymentAccountInfo>
</Report>  

ありがとうございました!

4

4 に答える 4

0

すべての xml ノードをコピーする通常の方法です。apply-templates を「node()」として選択した場合のみ

したがって、現在の XSLT は (多かれ少なかれ)

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match="@*|node()">
    <xsl:copy><xsl:apply-templates /></xsl:copy>
  </xsl:template>
</xsl:stylesheet>

AccountName要素内のテキスト ノードを抑制するには、追加のテンプレートを追加する必要があります

  <xsl:template match="AccountName/text()" />

これにより、目的のものが生成されます

<Report>   
    <PaymentAccountInfo>     
        <AccountName/>
    </PaymentAccountInfo>
</Report>

内部のテキスト ノードだけでなくすべてのテキスト ノードを削除する場合AccountName(空白のみのノードを押しつぶすため、インデントも削除されます)、match="text()"代わりに次のように使用します。match="AccountName/text()"

于 2013-06-26T14:09:54.890 に答える
0

すべての要素からテキスト コンテンツを削除する場合は、恒等変換を に置き換えnode()て変更できます*

ただし、これによりコメントと処理命令も削除されるため、次のいずれかになります。

  • comment()および/または( )processing-instruction()に追加**|comment()|processing-instruction()

また

  • 恒等変換はそのままにして、テンプレートを追加し<xsl:template match="text()"/>ます。

例:

XML 入力

<Report>   
    <PaymentAccountInfo>     
        <AccountName>Demo Disbursement Account</AccountName>
    </PaymentAccountInfo>
</Report>

XSLT1.0

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output indent="yes"/>
    <xsl:strip-space elements="*"/>

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

</xsl:stylesheet>

XML 出力

<Report>
   <PaymentAccountInfo>
      <AccountName/>
   </PaymentAccountInfo>
</Report>
于 2013-06-26T19:49:17.130 に答える
0

次のことを試すことができます。

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

<xsl:output method="xml" 
    indent="yes" />

<xsl:template match="*">
    <xsl:element name="{name()}">
        <xsl:apply-templates select="* | @*"/>
        <!--
        to also display text, change this line to
        <xsl:apply-templates select="* | @* | text()"/>
        -->
    </xsl:element>
</xsl:template>

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

</xsl:stylesheet>
于 2013-06-26T14:05:03.917 に答える