2015-11-05 52 views
-3

我有以下結構化源XML文檔:嘿guyz我一直在全國各地尋找解決方案,但沒有發現任何類似的事情:

<a> 
    <k> 
     <l> l_hello </l> 
    </k>   
    <b id="0"> 
     <c> 
     <d>d_hello</d> 
     </c> 
    </b> 
    <e id="0"> 
    <f> 
     <g> 
     <h>h_hello</h> 
     </g> 
    </f> 
    </e> 
</a> 

現在我想做的是......我想要重複整個<b>標記5次並且與之平行<e>標記5次,並具有所有的屬性。我的意思是說我想下面出去找生成:

<a> 
    <k> 
     <l> l_hello </l> 
    </k>   
    <b id="0"> 
     <c> 
     <d>d_hello</d> 
     </c> 
    </b> 
    <e id="0"> 
    <f> 
     <g> 
     <h>h_hello</h> 
     </g> 
    </f> 
    </e> 
    <b id="0"> 
     <c> 
     <d>d_hello</d> 
     </c> 
    </b> 
    <e id="0"> 
    <f> 
     <g> 
     <h>h_hello</h> 
     </g> 
    </f> 
    </e> 
    <b id="0"> 
     <c> 
     <d>d_hello</d> 
     </c> 
    </b> 
    <e id="0"> 
    <f> 
     <g> 
     <h>h_hello</h> 
     </g> 
    </f> 
    </e> 
    <b id="0"> 
     <c> 
     <d>d_hello</d> 
     </c> 
    </b> 
    <e id="0"> 
    <f> 
     <g> 
     <h>h_hello</h> 
     </g> 
    </f> 
    </e> 
    <b id="0"> 
     <c> 
     <d>d_hello</d> 
     </c> 
    </b> 
    <e id="0"> 
    <f> 
     <g> 
     <h>h_hello</h> 
     </g> 
    </f> 
    </e> 
</a> 

如果任何人都拿出一個解決辦法是有很大幫助....我已經生成的代碼,但是這是在粘貼都錯了所以沒有點這裏.....

+1

請註明XSLT 1.0或2.0。並改變你的標題爲更具描述性和適當的 –

回答

0

這裏是一個非常簡單的方法:

XSLT 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 

<xsl:template match="/a"> 
    <xsl:copy> 
     <xsl:copy-of select="k"/> 
     <xsl:copy-of select="b"/> 
     <xsl:copy-of select="e"/> 
     <xsl:copy-of select="b"/> 
     <xsl:copy-of select="e"/> 
     <xsl:copy-of select="b"/> 
     <xsl:copy-of select="e"/> 
     <xsl:copy-of select="b"/> 
     <xsl:copy-of select="e"/> 
     <xsl:copy-of select="b"/> 
     <xsl:copy-of select="e"/> 
    </xsl:copy> 
</xsl:template> 

</xsl:stylesheet> 

告訴我一些方法,其中比B和E之外的所有標籤都應該來一次 和B和E應重複5次

這也可以很簡單:

<xsl:template match="/a"> 
    <xsl:copy> 
     <xsl:copy-of select="*[not(self::b or self::e)]"/> 
     <xsl:variable name="be" select="b|e" /> 
     <xsl:copy-of select="$be"/> 
     <xsl:copy-of select="$be"/> 
     <xsl:copy-of select="$be"/> 
     <xsl:copy-of select="$be"/> 
     <xsl:copy-of select="$be"/> 
    </xsl:copy> 
</xsl:template> 
+0

感謝邁克爾這樣一個快速的答覆,但我想實現它與一個循環的幫助,是它的xslt 1.0 – Chetan

+0

我已經上傳的輸入XML的結構只是一個例如,我的XML幾乎有35000個標籤長,anywaz告訴我一些方法,除b和e之外的所有標籤都應該出現一次,b和e應該在循環的幫助下重複5次 – Chetan

+0

嘿邁克爾再次感謝您的快速幫助和它的工作.........我是新的xslt所以可能會在需要時尋求你的幫助............. – Chetan

相關問題