使用XSLT将html中的节点动态处理和排序为xml [英] Dynamically process and sort nodes in html to xml using XSLT

查看:87
本文介绍了使用XSLT将html中的节点动态处理和排序为xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个HTML文件,我只想使用XSLT转换为XML..

我要
1.要保留的所有节点.
2.所有元素都被排序.
3.并且代码应该动态地放在其中.

我有一个很大的文件,所以我想要一个简单的代码来处理所有html node.here,我用xslt解释了我的编码
如果您了解它,请帮助我.


我的HTML文件是..

I have an HTML file and i want to convert to XML only using XSLT..

I want
1.All the nodes to be retained.
2.And all elements are sorted.
3.And code should be in dynamically.

i have an huge file so i want an simple code to process all the html nodes.here i explained my codeing with the xslt
if u understand it plz help me..


My HTML file is..

<div id="2196" class="one_tail">
<span id="2197" class="one_biblio">
    <span id="2198" class="one_section-title">Title</span>
    <ol id="2199" class="one_biblio-sec">
        <li id="2200" class="one_bib-reference">
            <span id="2202" class="one_reference">
                <span id="2203" class="one_contribution">
                    <span id="2204" class="one_authors">
                        <span id="2205" class="one_author">

                            <!-- here the id value misplaced -->
                               <span id="2207" class="one_surname">Surname</span>
                            <span id="2206" class="one_given-name">GivenName</span>

                        </span>
                    </span>
                    <span id="2208" class="one_title">
                        <span id="2209" class="one_maintitle">technology</span>
                    </span>
                </span>
                <span id="2210" class="one_host">
                    <span id="2211" class="one_book">
                        <span id="2213" class="one_publisher">Publisher </span>
                    </span>
                </span>.
            </span>
        </li>
    </ol>
</span>
</div>


我想要的XML文件为:
这里,属性类的值用作元素名称.


And i want the XML file as:
Here the attribute class value is used as element name.

<tail id="2196">
<biblio id="2197">
    <section-title id="2198">Title</section-title>
    <biblio-sec id="2199">
        <bib-reference id="2200">
            <reference id="2202">
                <contribution id="2203">
                    <authors id="2204">
                        <author id="2205">
                                           <!-- correrct the id -->
                                <given-name id="2206">GivenName </given-name>
                            <surname id="2207">Surname</surname>
                             </author>
                    </authors>
                        <title id="2208" >
                                <maintitle id="2209">technology</maintitle>
                            </title>
                </contribution>
                </reference>
            <host id="2210">
                <book id="2211">
                    <publisher id="2213">Publisher </publisher>
                    </book>
                </host>
            </bib-reference>
               </biblio-sec>
        </biblio>
</tail>


我写的XSLT没有给出我想要的..
XSLT代码为:


The XSLT i wrote is not giving what i want..
The XSLT code is:

<xsl:template match="*|/" xmlns:xsl="#unknown">
        <xsl:for-each select=".">
                <xsl:for-each select="current()/*">
                  <xsl:sort select="@id" order="ascending" />
                         </xsl:for-each>
                 <xsl:if test="starts-with(@class,'one_') ">
                      <xsl:variable name="nodename" select="substring-after(@class,'one_')" />
                           <xsl:element name="{$nodename}">
                              <xsl:attribute name="id" select="@id" />
                           <xsl:apply-templates />
                        </xsl:element>
                      </xsl:if>
                      <xsl:if test="not(@class)">
                             <xsl:apply-templates />
                      </xsl:if>
              
        </xsl:for-each>                       
              </xsl:template>	


谁能帮助我..


Can any one help me..

推荐答案

nodename}" < xsl:attribute 名称 =" 选择 @ id" / < xsl:apply-templates / > < /xsl:element > < /xsl:if > < xsl:if 测试 =" > < xsl:apply-templates / > < /xsl:if > < /xsl:for-each > < /xsl:template >
nodename}"> <xsl:attribute name="id" select="@id" /> <xsl:apply-templates /> </xsl:element> </xsl:if> <xsl:if test="not(@class)"> <xsl:apply-templates /> </xsl:if> </xsl:for-each> </xsl:template>


谁能帮助我..


Can any one help me..


这篇关于使用XSLT将html中的节点动态处理和排序为xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆