Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
xslt:将所有同级移动到第一个同级中_Xslt - Fatal编程技术网

xslt:将所有同级移动到第一个同级中

xslt:将所有同级移动到第一个同级中,xslt,Xslt,我搜索过类似的问题,但没有提出任何可行的建议。我有以下xml,我需要修改它 <XDB> <ROOT> <KEY><ID>12345</ID><DATE>5/10/2011</DATE></KEY> <PERSONAL><ID>1</ID><INFO><LASTNAME>Smith<

我搜索过类似的问题,但没有提出任何可行的建议。我有以下xml,我需要修改它

  <XDB>
     <ROOT>
           <KEY><ID>12345</ID><DATE>5/10/2011</DATE></KEY>
           <PERSONAL><ID>1</ID><INFO><LASTNAME>Smith</LASTNAME>...</INFO></PERSONAL>
           <CONTACT><ID>1</ID><EMAIL>asmith@yahoo.com</EMAIL>...</CONTACT>
     </ROOT>
    <ROOT>
           <KEY><ID>98765</ID><DATE>5/10/2013</DATE></KEY>
           <CONTACT><ID>2</ID><EMAIL>psmithton@yahoo.com</EMAIL>...</CONTACT>
     </ROOT>

123455/10/2011
第1次。。。
1asmith@yahoo.com...
987655/10/2013
2psmithton@yahoo.com...


它需要像这样:

 <XDB>
     <ROOT>
       <KEY><ID>12345</ID><DATE>5/10/2011</DATE>
           <PERSONAL><ID>1</ID><INFO><LASTNAME>Smith</LASTNAME>...</INFO></PERSONAL>
           <CONTACT><ID>1</ID><EMAIL>asmith@yahoo.com</EMAIL>...</CONTACT>
        </KEY>

     </ROOT>
    <ROOT>
       <KEY><ID>98765</ID><DATE>5/10/2013</DATE>
           <CONTACT><ID>2</ID><EMAIL>psmithton@yahoo.com</EMAIL>...</CONTACT>
       </KEY>
     </ROOT>

123455/10/2011
第1次。。。
1asmith@yahoo.com...
987655/10/2013
2psmithton@yahoo.com...


我需要让2…n个兄弟姐妹成为第一个“关键”兄弟姐妹的孩子。基本上,我需要删除结束并将其放在结束之前。谢谢你的帮助。 谢谢。

遵循基于的xslt可以完成这项工作

<?xml version="1.0" encoding="UTF-8"?>
<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"/>

    <!-- Copy everything you find... -->
    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*" />
        </xsl:copy>
    </xsl:template>

    <!-- ... but if you find first element inside ROOT ... -->
    <xsl:template match="ROOT/node()[1]">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*" />
            <!-- ... copy its sibling into it ... -->
            <xsl:copy-of select="following-sibling::*" />
        </xsl:copy>
    </xsl:template>

    <!-- ignore other elements inside ROOT element since they are copied in template matching first element -->
    <xsl:template match="ROOT/node()[position() &gt; 1]" />

</xsl:stylesheet>

非常感谢您。这正是我想做的!
  </XDB>
<?xml version="1.0" encoding="UTF-8"?>
<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"/>

    <!-- Copy everything you find... -->
    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*" />
        </xsl:copy>
    </xsl:template>

    <!-- ... but if you find first element inside ROOT ... -->
    <xsl:template match="ROOT/node()[1]">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*" />
            <!-- ... copy its sibling into it ... -->
            <xsl:copy-of select="following-sibling::*" />
        </xsl:copy>
    </xsl:template>

    <!-- ignore other elements inside ROOT element since they are copied in template matching first element -->
    <xsl:template match="ROOT/node()[position() &gt; 1]" />

</xsl:stylesheet>