2

我有这个xml

<quran>
    <row>
        <WID>10</WID>
        <word>بسم</word>
        <SID>1</SID>
        <Ayeh>0</Ayeh>
        <Joze>1</Joze>
        <Hezb>1</Hezb>
        <ParentID>4556</ParentID>
        <Page>1</Page>
        <Joint>1</Joint>
        <SName>فاتحه</SName>
    </row>
    <row>
        <WID>11</WID>
        <word>الله</word>
        <SID>1</SID>
        <Ayeh>0</Ayeh>
        <Joze>1</Joze>
        <Hezb>1</Hezb>
        <ParentID>3565</ParentID>
        <Page>1</Page>
        <Joint>1</Joint>
        <SName>فاتحه</SName>
    </row>
    <row>
        <WID>12</WID>
        <word>الرحمن</word>
        <SID>1</SID>
        <Ayeh>0</Ayeh>
        <Joze>1</Joze>
        <Hezb>1</Hezb>
        <ParentID>2876</ParentID>
        <Page>1</Page>
        <Joint>1</Joint>
        <SName>فاتحه</SName>
    </row>
    <row>
        <WID>14</WID>
        <word>الْحَمْدُ</word>
        <SID>1</SID>
        <Ayeh>2</Ayeh>
        <Joze>1</Joze>
        <Hezb>1</Hezb>
        <ParentID>2732</ParentID>
        <Page>1</Page>
        <Joint>1</Joint>
        <SName>فاتحه</SName>
    </row>
    <row>
        <WID>15</WID>
        <word>للّهِ</word>
        <SID>1</SID>
        <Ayeh>2</Ayeh>
        <Joze>1</Joze>
        <Hezb>1</Hezb>
        <ParentID>12105</ParentID>
        <Page>1</Page>
        <Joint>1</Joint>
        <SName>فاتحه</SName>
    </row>
    <row>
        <WID>5618</WID>
        <word>بسم</word>
        <SID>2</SID>
        <Ayeh>0</Ayeh>
        <Joze>1</Joze>
        <Hezb>1</Hezb>
        <ParentID>4556</ParentID>
        <Page>2</Page>
        <Joint>2</Joint>
        <SName>بقره</SName>
    </row>
    <row>
        <WID>5619</WID>
        <word>الله</word>
        <SID>2</SID>
        <Ayeh>0</Ayeh>
        <Joze>1</Joze>
        <Hezb>1</Hezb>
        <ParentID>3565</ParentID>
        <Page>2</Page>
        <Joint>2</Joint>
        <SName>بقره</SName>
    </row>
    <row>
        <WID>5620</WID>
        <word>الرحمن</word>
        <SID>2</SID>
        <Ayeh>0</Ayeh>
        <Joze>1</Joze>
        <Hezb>1</Hezb>
        <ParentID>2876</ParentID>
        <Page>2</Page>
        <Joint>2</Joint>
        <SName>بقره</SName>
    </row>
    <row>
        <WID>4784</WID>
        <word>الم</word>
        <SID>2</SID>
        <Ayeh>1</Ayeh>
        <Joze>1</Joze>
        <Hezb>1</Hezb>
        <ParentID>3567</ParentID>
        <Page>2</Page>
        <Joint>2</Joint>
        <SName>بقره</SName>
    </row>
    <row>
        <WID>5105</WID>
        <word>ذَلِكَ</word>
        <SID>2</SID>
        <Ayeh>2</Ayeh>
        <Joze>1</Joze>
        <Hezb>1</Hezb>
        <ParentID>7234</ParentID>
        <Page>2</Page>
        <Joint>2</Joint>
        <SName>بقره</SName>
    </row>
    <quran>

我需要插入<SName>之前的标签<Ayeh>,即<Ayeh>0</Ayeh>. 我写了一个 jquery 代码,但我不知道如何在 jquery 中使用 xslt?(下面的代码不起作用)

$('.quranText .ayaNumber').each(function(){
    if($.trim($(this).text())=='﴿0﴾')
       $(this).closest('.aya').prepend('<div class="suraHeaderFrame">'
                    +'<div class="suraHeaderText">'+ 

                                        <xsl:for-each-group select="//row[./Page/text()=$page]" group-by="Page">
                                            <xsl:for-each-group select="current-group()" group-by="SID">
                                                <xsl:for-each-group select="current-group()" group-by="concat(Page,SID)">
                                                <xsl:choose > 
                                                     <xsl:when test = "./Ayeh = 1 or ./Ayeh = 0" >  
                                                    <xsl:value-of select="SName"/>
                                                        </xsl:when>
                                                  </xsl:choose>
                                                </xsl:for-each-group>
                                            </xsl:for-each-group>
                                        </xsl:for-each-group>

 +'</div>'
                +'</div>');
});

我应该说,通常在一页中有很多<Ayeh>0</Ayeh>. 我正在写一个同样的网站:http ://tanzil.net/#109:1 。

4

1 回答 1

0

看起来你应该使用 parseXML http://api.jquery.com/jQuery.parseXML/

var xml = "<?xml version='1.0'?><quran><row><WID>10</WID><word>بسم</word><SID>1</SID><Ayeh>0</Ayeh><Joze>1</Joze><Hezb>1</Hezb><ParentID>4556</ParentID><Page>1</Page><Joint>1</Joint><SName>فاتحه</SName></row><row><WID>11</WID><word>الله</word><SID>1</SID><Ayeh>0</Ayeh><Joze>1</Joze><Hezb>1</Hezb><ParentID>3565</ParentID><Page>1</Page><Joint>1</Joint><SName>فاتحه</SName></row><row><WID>12</WID><word>الرحمن</word><SID>1</SID><Ayeh>0</Ayeh><Joze>1</Joze><Hezb>1</Hezb><ParentID>2876</ParentID><Page>1</Page><Joint>1</Joint><SName>فاتحه</SName></row><row><WID>14</WID><word>الْحَمْدُ</word><SID>1</SID><Ayeh>2</Ayeh><Joze>1</Joze><Hezb>1</Hezb><ParentID>2732</ParentID><Page>1</Page><Joint>1</Joint><SName>فاتحه</SName></row><row><WID>15</WID><word>للّهِ</word><SID>1</SID><Ayeh>2</Ayeh><Joze>1</Joze><Hezb>1</Hezb><ParentID>12105</ParentID><Page>1</Page><Joint>1</Joint><SName>فاتحه</SName></row><row><WID>5618</WID><word>بسم</word><SID>2</SID><Ayeh>0</Ayeh><Joze>1</Joze><Hezb>1</Hezb><ParentID>4556</ParentID><Page>2</Page><Joint>2</Joint><SName>بقره</SName></row><row><WID>5619</WID><word>الله</word><SID>2</SID><Ayeh>0</Ayeh><Joze>1</Joze><Hezb>1</Hezb><ParentID>3565</ParentID><Page>2</Page><Joint>2</Joint><SName>بقره</SName></row><row><WID>5620</WID><word>الرحمن</word><SID>2</SID><Ayeh>0</Ayeh><Joze>1</Joze><Hezb>1</Hezb><ParentID>2876</ParentID><Page>2</Page><Joint>2</Joint><SName>بقره</SName></row><row><WID>4784</WID><word>الم</word><SID>2</SID><Ayeh>1</Ayeh><Joze>1</Joze><Hezb>1</Hezb><ParentID>3567</ParentID><Page>2</Page><Joint>2</Joint><SName>بقره</SName></row><row><WID>5105</WID><word>ذَلِكَ</word><SID>2</SID><Ayeh>2</Ayeh><Joze>1</Joze><Hezb>1</Hezb><ParentID>7234</ParentID><Page>2</Page><Joint>2</Joint><SName>بقره</SName></row></quran>"
xmlDoc = $.parseXML( xml ),
$xml = $( xmlDoc ),
$xml.find( "SName" ).each(function(){
    $(this).siblings('Ayeh').before($(this));
})

这会将 SName 节点移动到其兄弟 Ayeh 节点之前。然后 $xml[0] 将成为您可以使用的 xml 文档,或者您可以将 jQuery 对象 $xml 附加到您的 div。

于 2013-08-11T08:08:40.440 回答