转换最后N个元素

时间:2018-03-08 04:11:31

标签: xml xslt

我有以下xml结构

         <HTTPSamplerProxy guiclass="HttpTestSampleGui" testname="21 /en/" enabled="false">
            <elementProp name="HTTPsampler.Arguments" elementType="Arguments">
              <collectionProp name="Arguments.arguments"/>
            </elementProp>
            <stringProp name="HTTPSampler.implementation">HttpClient4</stringProp>
            <boolProp name="HTTPSampler.follow_redirects">true</boolProp>
            <boolProp name="HTTPSampler.use_keepalive">false</boolProp>
            <stringProp name="HTTPSampler.domain">moulin.nl</stringProp>
            <stringProp name="HTTPSampler.method">GET</stringProp>
            <stringProp name="HTTPSampler.port">443</stringProp>
            <stringProp name="HTTPSampler.protocol">https</stringProp>
            <stringProp name="HTTPSampler.path">/en/</stringProp>
            <elementProp name="HTTPSampler.header_manager" elementType="HeaderManager" guiclass="HeaderPanel" testclass="HeaderManager" testname="HTTP Header Manager" enabled="true">
              <collectionProp name="HeaderManager.headers">
                <elementProp name="Cache-Control" elementType="Header">
                  <stringProp name="Header.name">Cache-Control</stringProp>
                  <stringProp name="Header.value">no-cache</stringProp>
                </elementProp>
                <elementProp name="Accept-Encoding" elementType="Header">
                  <stringProp name="Header.name">Accept-Encoding</stringProp>
                  <stringProp name="Header.value">gzip</stringProp>
                </elementProp>
                <elementProp name="Pragma" elementType="Header">
                  <stringProp name="Header.name">Pragma</stringProp>
                  <stringProp name="Header.value">no-cache</stringProp>
                </elementProp>
                <elementProp name="User-Agent" elementType="Header">
                  <stringProp name="Header.name">User-Agent</stringProp>
                  <stringProp name="Header.value">Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.112 Safari/535.1</stringProp>
                </elementProp>
                <elementProp name="Accept" elementType="Header">
                  <stringProp name="Header.name">Accept</stringProp>
                  <stringProp name="Header.value">text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2</stringProp>
                </elementProp>
              </collectionProp>
            </elementProp>
            <stringProp name="TestPlan.comments">Detected a redirect from the previous sample</stringProp>
            <boolProp name="HTTPSampler.auto_redirects">false</boolProp>
            <boolProp name="HTTPSampler.image_parser">true</boolProp>
          </HTTPSamplerProxy>
          <hashTree>
            <HeaderManager guiclass="HeaderPanel" testclass="HeaderManager" testname="HTTP Header Manager" enabled="true">
              <collectionProp reference="../../../HTTPSamplerProxy[3]/elementProp[2]/collectionProp"/>
            </HeaderManager>
            <hashTree/>
          </hashTree>

我希望进行以下转换

1)将<collectionProp reference ... />替换为<collectionProp name="HeaderManager.headers">元素。

2)删除有孩子的<elementProp name="HTTPSampler.header_manager" ... >

3)上面的xml结构(HTTPSamplerProxy - hashTree组合 - 兄弟姐妹)在一个xml文件中重复多次,因此上面两点应该适用于所有重复的xml结构({{ 1}} - HTTPSamplerProxy combo - 兄弟姐妹)。

4)也可以选择最后N个xml-strucutres(hashTree - HTTPSamplerProxy组合 - 兄弟姐妹)

我已经尝试了少数 xslt转换,但无法达到预期效果。

现在下面是整个xml文件

hashTree

0 个答案:

没有答案