0

次のような XML からタグを削除しようとしています。

<vocabularyModel>
<conceptDomain name="ActAccountType">
    <annotations>
        <documentation>
            <definition>
                <text>
                    <p>
                        <b>Description: </b>more txt here </p>
                    <p>
                        <i>Examples: </i>
                    </p>
                    <p/>
                    <ul>
                        <li>
                            <p>Patient billing accounts</p>
                        </li>
                        <li>
                            <p>Cost center</p>
                        </li>
                        <li>
                            <p>Cash</p>
                        </li>
                    </ul>
                </text>
            </definition>
        </documentation>
    </annotations>
</conceptDomain>
<conceptDomain name="ActAdjudicationInformationCode">
    <annotations>
        <documentation>
            <definition>
                <text>
                    <p>long text.</p>
                    <p>long text.</p>
                    <p>long text.</p>
                    <p>long text.</p>
                </text>
            </definition>
        </documentation>
    </annotations>
</conceptDomain>
<conceptDomain name="ActAdjudicationType">
    <annotations>
        <documentation>
            <definition>
                <text>
                    <p>
                        <b>Description: </b>more text.</p>
                    <p>
                        <i>Examples: </i>
                    </p>
                    <p/>
                    <ul>
                        <li>
                            <p>adjudicated with adjustments</p>
                        </li>
                        <li>
                            <p>adjudicated as refused</p>
                        </li>
                        <li>
                            <p>adjudicated as submitted</p>
                        </li>
                    </ul>
                </text>
            </definition>
        </documentation>
    </annotations>
</conceptDomain>

テキストの下の子タグはすべて削除されますが、目的の xml とテキストは次のようになります。

<vocabularyModel>
<conceptDomain name="ActAccountType">
    <annotations>
        <documentation>
            <definition>
                <text>
                   Description: more txt here 
                        Examples: 
                          Patient billing accounts
                          Cost center
                          Cash
                </text>
            </definition>
        </documentation>
    </annotations>
</conceptDomain>
<conceptDomain name="ActAdjudicationInformationCode">
    <annotations>
        <documentation>
            <definition>
                <text>
                    long text.
                    long text.
                    long text.
                    long text.
                </text>
            </definition>
        </documentation>
    </annotations>>
</conceptDomain>
<conceptDomain name="ActAdjudicationReason">
    <annotations>
        <documentation>
            <definition>
                <text>
                    long text.
                    long text.
                    long text.
                    long text.
                </text>
            </definition>
        </documentation>
    </annotations>
    <specializesDomain name="ActReason"/>
</conceptDomain>
<conceptDomain name="ActAdjudicationType">
    <annotations>
        <documentation>
            <definition>
                <text>
                        Description: more text.
                        Examples: 
                            adjudicated with adjustments
                            adjudicated as refused
                            adjudicated as submitted
                </text>
            </definition>
        </documentation>
    </annotations>
</conceptDomain>

ここの他の場所で見つかった次のことを試して変更しました:

<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>

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

<xsl:template match="p | b | li | ul | i">
    <xsl:apply-templates/>
</xsl:template>

しかし、一致を要素のみに制限した場合でも、これは要素を削除しませんでした。また、次のいくつかのバリエーションを試しました。

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


<xsl:template name="strip-tags">
    <xsl:param name="html"/>
    <xsl:choose>
        <xsl:when test="contains($html, '&lt;')">
            <xsl:value-of select="substring-before($html, '&lt;')"/>
            <xsl:call-template name="strip-tags">
                <xsl:with-param name="html" select="substring-after($html, '&gt;')"/>
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$html"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>


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

<xsl:template match="definition">
    <xsl:call-template name="strip-tags">
        <xsl:with-param name="html" select="text"/>
    </xsl:call-template>
</xsl:template>

ID 変換を省略するとすべてのタグが削除されますが、それ以外の場合は元の XML のコンテンツをコピーするだけです。どんな助けでも大歓迎です。-スコット

4

1 に答える 1