2017-02-04 4 views
2

でXML要素とコンマ別々の名前を変更します。ここで
は私のXMLである:ここではは私がやりたいことはiavmNotice/iavmTitleにiavmNotice /タイトルの名前を変更しているXSLT

<iavmNotice xmlns="http://stuff.com" noticeId="138643"> 
    <title>Cisco Vulnerability</title> 
    <techOverview> 
     <entry> 
     <title>2012-2490</title> 
     <description>Cisco ID 71.</description> 
     </entry> 
     <entry> 
     <title>2012-2525</title> 
     <description>Cisco ID 69.</description> 
     </entry> 
    </techOverview> 
</iavmNotice> 

は私の試みです:

<xsl:template match="@* | node()"> 
    <xsl:copy> 
     <xsl:apply-templates select="@* | node()"/> 
    </xsl:copy> 
</xsl:template> 
<xsl:template match="iavmNotice/title"> 
    <iavmTitle> 
    <xsl:apply-templates select="@* | node()"/> 
    </iavmTitle> 
</xsl:template> 
<xsl:template match="@iavmNotice/title"> 
    <xsl:attribute name="iavmTitle"> 
    <xsl:value-of select="."/> 
</xsl:attribute> 
</xsl:template> 

また、techOverview/entry/titleをコンマで区切ってインポートする方法もありますか? 2012-2490、2012-2525としてインポートして説明を削除してください。

答えて

2

XMLドキュメントのiavmNoticeルート要素のxmlns="http://stuff.com"宣言は、ドキュメント全体をhttp://stuff.com名前空間に置きます。

だからどちらか、その名前空間のあなたのスタイルシートを認識させる必要があり、さもなければ、あなたの一致にはちょうどlocal-name()を使用します。

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:template match="@* | node()"> 
    <xsl:copy> 
     <xsl:apply-templates select="@* | node()"/> 
    </xsl:copy> 
    </xsl:template> 
    <xsl:template match="*[local-name() = 'iavmNotice']/*[local-name() = 'title']"> 
    <iavmTitle> 
     <xsl:apply-templates select="@* | node()"/> 
    </iavmTitle> 
    </xsl:template> 
</xsl:stylesheet> 
+1

グレート答え!どうもありがとうございました! techOverview/entry/titleをコンマで区切ってインポートする方法はありますか? 2012-2490、2012-2525としてインポートして説明を削除してください – jjohnson

+0

問題を説明する特定のタイトルで個別の質問として投稿すると、おそらくそれで幸運になります – sideshowbarker

関連する問題