使用xslt基于其他节点重新构造xml节点

使用xslt基于其他节点重新构造xml节点,xslt,xslt-2.0,Xslt,Xslt 2.0,我有以下xml <xml> <object context="3-cumulative" > <metadata> <ref cite="4.2" relevance="first.2"/> </metadata> <body> <para> <text> applicable on and after December 14,2007. </t

我有以下xml

<xml>
  <object context="3-cumulative" >
  <metadata>
  <ref cite="4.2" relevance="first.2"/>
  </metadata>
<body>
  <para>
    <text> 
      applicable on and after December 14,2007.
    </text>
  </para>
</body>
</object>
<object context="3-cumulative" >
  <metadata>
  <ref cite="4.2" relevance="first.1"/>
  </metadata>
<body>
  <para>
    <text> 
      applicable on and after December 14,2006.
    </text>
  </para>
</body>
</object>

 <object context="3-cumulative" >
 <metadata>
  <related-content-ref cite="5 annuity" relevance="first.1"/>
</metadata>
<body>
  <para>
     <text>
       applicable on and after December 14, 2008
     </text>
   </para>
 </body>
</object>
   <mainbody>
      <num cite="4.2">4.2</num>
      <heading>Stock exchanges</heading>
      <prov-body>
        <text>
           Notwithstanding the provisions of a convention ... as defined in the
           <italic>Income Tax Act</italic>.
        </text>
     <prov>
            <num cite="5 annuity"/>
            <heading>“annuity”</heading>
            <text>
            <term>“annuity”</term>does not include any pension payment ...
           </text>
            <text>
            any pension payment ...
           </text>
  </prov>
 </prov-body>
  </mainbody>
 </xml>  

2007年12月14日及之后适用。
2006年12月14日及之后适用。
2008年12月14日及之后适用
4.2
证券交易所
尽管有公约的规定。。。如
所得税法。
“年金”
“年金”不包括任何养老金支付。。。
任何养老金支付。。。
我需要查看是否在“mainbody”num/@cite中找到任何对象/metadata/ref/@cite,然后对象中的para/text应复制到第一个文本节点的末尾,并应按对象/metadata/ref/@relevance排序

输出应为:

<xml>
 <mainbody>
 <num cite="4.2">4.2</num>
 <heading>Stock exchanges</heading>
 <prov-body>
  <text>
    Notwithstanding the provisions of a convention ... as defined in the
    <italic>Income Tax Act</italic>.
    **applicable on and after December 14, 2006**
    **applicable on and after December 14, 2007**
  </text>
 <prov>
        <num cite="5 annuity"/>
        <heading>“annuity”</heading>
        <text>
        <term>“annuity”</term>does not include any pension payment ...
         **applicable on and after December 14, 2008**
        </text>
        <text>
        any pension payment ...
       </text>
   </prov>
  </prov-body>
 </mainbody>
</xml>  

4.2
证券交易所
尽管有公约的规定。。。如
所得税法。
**2006年12月14日及之后适用**
**2007年12月14日及之后适用**
“年金”
“年金”不包括任何养老金支付。。。
**2008年12月14日及之后适用**
任何养老金支付。。。

此XSLT 1.0转换(如果将
version
属性更改为2.0,并使用XSLT 2.0处理器运行转换,则会产生相同的结果):


应用于提供的XML文档时:

<xml>
    <object context="3-cumulative" >
        <metadata>
            <ref cite="4.2" relevance="first.2"/>
        </metadata>
        <body>
            <para>
                <text>
          applicable on and after December 14,2007.
                </text>
            </para>
        </body>
    </object>
    <object context="3-cumulative" >
        <metadata>
            <ref cite="4.2" relevance="first.1"/>
        </metadata>
        <body>
            <para>
                <text>
          applicable on and after December 14,2006.
                </text>
            </para>
        </body>
    </object>
    <object context="3-cumulative" >
        <metadata>
            <related-content-ref cite="5 annuity" relevance="first.1"/>
        </metadata>
        <body>
            <para>
                <text>
           applicable on and after December 14, 2008
                </text>
            </para>
        </body>
    </object>
    <mainbody>
        <num cite="4.2">4.2</num>
        <heading>Stock exchanges</heading>
        <prov-body>
            <text>
        Notwithstanding the provisions of a convention ... as defined in the
                <italic>Income Tax Act</italic>.
            </text>
            <prov>
                <num cite="5 annuity"/>
                <heading>“annuity”</heading>
                <text>
                    <term>“annuity”</term>does not include any pension payment ...
                </text>
                <text>
           any pension payment ...
                </text>
            </prov>
        </prov-body>
    </mainbody>
</xml>
<xml>
   <mainbody>
      <num cite="4.2">4.2</num>
      <heading>Stock exchanges</heading>
      <prov-body>
         <text>
        Notwithstanding the provisions of a convention ... as defined in the
                <italic>Income Tax Act</italic>.

          applicable on and after December 14,2006.

          applicable on and after December 14,2007.
                </text>
         <prov>
            <num cite="5 annuity"/>
            <heading>“annuity”</heading>
            <text>
               <term>“annuity”</term>does not include any pension payment ...

           applicable on and after December 14, 2008
                </text>
            <text>
           any pension payment ...
                </text>
         </prov>
      </prov-body>
   </mainbody>
</xml>

2007年12月14日及之后适用。
2006年12月14日及之后适用。
2008年12月14日及之后适用
4.2
证券交易所
尽管有公约的规定。。。如
所得税法。
“年金”
“年金”不包括任何养老金支付。。。
任何养老金支付。。。
生成所需的正确结果:

<xml>
    <object context="3-cumulative" >
        <metadata>
            <ref cite="4.2" relevance="first.2"/>
        </metadata>
        <body>
            <para>
                <text>
          applicable on and after December 14,2007.
                </text>
            </para>
        </body>
    </object>
    <object context="3-cumulative" >
        <metadata>
            <ref cite="4.2" relevance="first.1"/>
        </metadata>
        <body>
            <para>
                <text>
          applicable on and after December 14,2006.
                </text>
            </para>
        </body>
    </object>
    <object context="3-cumulative" >
        <metadata>
            <related-content-ref cite="5 annuity" relevance="first.1"/>
        </metadata>
        <body>
            <para>
                <text>
           applicable on and after December 14, 2008
                </text>
            </para>
        </body>
    </object>
    <mainbody>
        <num cite="4.2">4.2</num>
        <heading>Stock exchanges</heading>
        <prov-body>
            <text>
        Notwithstanding the provisions of a convention ... as defined in the
                <italic>Income Tax Act</italic>.
            </text>
            <prov>
                <num cite="5 annuity"/>
                <heading>“annuity”</heading>
                <text>
                    <term>“annuity”</term>does not include any pension payment ...
                </text>
                <text>
           any pension payment ...
                </text>
            </prov>
        </prov-body>
    </mainbody>
</xml>
<xml>
   <mainbody>
      <num cite="4.2">4.2</num>
      <heading>Stock exchanges</heading>
      <prov-body>
         <text>
        Notwithstanding the provisions of a convention ... as defined in the
                <italic>Income Tax Act</italic>.

          applicable on and after December 14,2006.

          applicable on and after December 14,2007.
                </text>
         <prov>
            <num cite="5 annuity"/>
            <heading>“annuity”</heading>
            <text>
               <term>“annuity”</term>does not include any pension payment ...

           applicable on and after December 14, 2008
                </text>
            <text>
           any pension payment ...
                </text>
         </prov>
      </prov-body>
   </mainbody>
</xml>

4.2
证券交易所
尽管有公约的规定。。。如
所得税法。
2006年12月14日及之后适用。
2007年12月14日及之后适用。
“年金”
“年金”不包括任何养老金支付。。。
2008年12月14日及之后适用
任何养老金支付。。。
说明


适当覆盖并使用功能。

您在等待什么?当您遇到问题时,请告诉我们!我只是想知道如何启动它,我正在使用key从object/metadata/ref/@cite获取cites,如何匹配文本emlment?我需要匹配引用的每个集合的第一个文本元素。您的示例“预期输出”格式不正确。请更正。不是允许的元素名称,即使是,也没有与此起始标记匹配的结束标记。哇。。。非常感谢。它就像一个魔咒,只是被修改成。只需要一个基于上下文类型的附加stuf,就可以在文本元素之前和之后插入值。因此,如果type=“3-cumulative”,则应如上所述。如果type=“1-cummulative”,那么我希望它在前面,如果是2-cummulative,那么在后面插入,而不是在文本中相互关联。我确实尝试过这样做,但不是期望的结果。。。有什么想法吗,迪米特?阿提夫:你原来的问题已经完全回答了。原始问题可能会有无限的“小”修改,将其作为问题的小修改添加是不正确的。请好好想想到底需要什么,然后问一个新问题。现在是晚上,所以我很乐意明天早上看看你可能发布的任何新问题。Dimitre,我能够解决上面提到的评论,但如果我在I-e 4.2 123中有2个num节点,我会坚持它查找最后一个num,如果我们有可能在tempalte match中查找所有num值???@atif:comments格式不适合发布评论。请问一个新问题,我很乐意回答。包括新XML的完整实例、转换必须实现的所有规则以及所需的完整结果。