2

空/自己終了タグにテキストを追加しようとしています。

" <empty/> " のようなものを " <empty> some text </empty> "に変換したいと思います。

これは、私が取り組んでいる xml の短縮版です。

<?xml version="1.0" encoding="UTF-8"?>
<dataset>
<attr tag="00080090" vr="PN" pos="-1" name="Referring Physician's Name" vm="0" len="0"/>
</dataset>

私はこの結果を得たい:

<?xml version="1.0" encoding="UTF-8"?>
<dataset>
<attr tag="00080090" vr="PN" pos="-1" name="Referring Physician's Name" vm="0" len="0">this is the inserted text</attr>
</dataset>

しかし、代わりに、変更されていないxmlになります。このタグにテキストが存在しない場合、一致が機能していないようです。すでにテキストがある場合は機能します。この場合、テキストを置き換えます。これは私にとっては問題ありません。

私のXSL(T)は次のようになります:

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

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

<xsl:template match="attr[@tag='00080090']/text()">
  <xsl:text>this is the inserted text</xsl:text>
</xsl:template>

</xsl:stylesheet>

http://xslttest.appspot.comでテストを行いました

ヒントはありますか?

4

1 に答える 1

3

XSLT は次のようになります。

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="xml" indent="no"/>
    <xsl:template match="node() | @*">
        <xsl:copy>
            <xsl:apply-templates select="node() | @*"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="attr[@tag='00080090']">
        <xsl:copy>
            <xsl:apply-templates select="@*"/>
            <xsl:text>this is the inserted text</xsl:text>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>
于 2013-07-26T13:10:11.830 に答える