1

私は XML を持っています。その XML には要素 <storybody> があり、それ自体にいくつかの要素があります。今、私が望むのは、<storybody> のすべてをコピーし、<storybody> の <URI> タグを <a> に変更することです。

ドキュメント内の <storybody> に対してのみこれを行う必要があることを思い出してください。

XML 構造:

<mothertag>
     <atag>
        asdfasdfa
     </atag>

     <storybody>
        <p>sometext here<URI ref="http://google.com" /> some more text</p>
     </storybody>
</mothertag>

次に、この URI をタグに変更します。

4

1 に答える 1

0

名前を変更するノードに一致するように、追加のテンプレートで拡張された恒等変換が必要になります。このような:

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

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

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

</xsl:stylesheet>

storybodyに適用した場合 (終了タグのタイプミスを修正):

<mothertag>
     <atag>
        asdfasdfa
     </atag>

     <storybody>
        <p>sometext here<URI ref="http://google.com" /> some more text</p>
     </storybody>

</mothertag>

プロデュース:

<mothertag>
   <atag>
      asdfasdfa

   </atag>
   <storybody>
      <p>sometext here
         <TAG ref="http://google.com"></TAG> some more text
      </p>
   </storybody>
</mothertag>
于 2012-05-10T12:28:02.040 に答える