将XML元素值迁移到属性值

时间:2017-09-18 09:55:53

标签: xml xslt

我有以下xml

<?xml version="1.0"?>
<BLOG blogsiteurl="url">
    <ARTICLES>
        <ARTICLE id="article1">
            <TITLE id="title1">A Sample Article</TITLE>
            <SECT>The First Major Section
                <PARA>This section will introduce a subsection.</PARA>
                    <PARA>This is the text of the subsection.
                    </PARA>
                    <RATING>3.4</RATING>
            </SECT>
        </ARTICLE>
        <ARTICLE id="article2">
            <TITLE id="title2">A Sample Article</TITLE>
            <SECT>The First Major Section
                <PARA>This section will introduce a subsection.</PARA>
                    <PARA>This is the text of the subsection.
                    </PARA>
                    <RATING>4.5</RATING>
            </SECT>
        </ARTICLE>
    </ARTICLES>
</BLOG>

我希望将RATING元素的值迁移到其中一个属性值,如下所示:

<?xml version="1.0"?>
<BLOG blogsiteurl="url">
    <ARTICLES>
        <ARTICLE id="article1">
            <TITLE id="title1">A Sample Article</TITLE>
            <SECT>The First Major Section
                <PARA>This section will introduce a subsection.</PARA>
                    <PARA>This is the text of the subsection.
                    </PARA>
            <RATING value="3.4"></RATING>
            </SECT>
        </ARTICLE>
        <ARTICLE id="article2">
            <TITLE id="title2">A Sample Article</TITLE>
            <SECT>The First Major Section
                <PARA>This section will introduce a subsection.</PARA>
                    <PARA>This is the text of the subsection.
                    </PARA>
            <RATING value="4.5"></RATING>
            </SECT>
        </ARTICLE>
    </ARTICLES>
</BLOG>

如何使用xlst实现这一目标?还有其他比xslt更好的方法吗?

0 个答案:

没有答案