带标识模板的XSLT递归

时间:2016-11-01 18:04:22

标签: xslt

我正在尝试使用身份模板从输入xml中获取所需的xml,这涉及到递归。

在输入xml中,我引用了最顶层节点,其子节点如下

<?xml version="1.0"?>
<referenced>
  <name>PocTree/PocTree.services:getReferencesForServices</name>
  <LOCK_STATUS>3</LOCK_STATUS>
  <type>
    <svc_type>flow</svc_type>
    <svc_subtype>default</svc_subtype>
  </type>
  <path/>
  <isPub>false</isPub>
  <isNotification>false</isNotification>
  <isFlowServiceDisabled>false</isFlowServiceDisabled>
  <status>reference</status>
  <reference>
    <name>WmRoot/wm.server.ns.dependency:getReferenced</name>
    <LOCK_STATUS>2</LOCK_STATUS>
    <type>
      <svc_type>java</svc_type>
      <svc_subtype>unknown</svc_subtype>
    </type>
    <path>/Flow Path;1.0/INVOKE;0</path>
    <isPub>false</isPub>
    <isNotification>false</isNotification>
    <isFlowServiceDisabled>false</isFlowServiceDisabled>
    <status>resolved</status>
  </reference>
  <reference>
    <name>WmPublic/pub.xml:documentToXMLString</name>
    <LOCK_STATUS>2</LOCK_STATUS>
    <type>
      <svc_type>java</svc_type>
      <svc_subtype>unknown</svc_subtype>
    </type>
    <path>/Flow Path;1.0/INVOKE;1</path>
    <isPub>false</isPub>
    <isNotification>false</isNotification>
    <isFlowServiceDisabled>false</isFlowServiceDisabled>
    <status>resolved</status>
  </reference>
  <reference>
    <name>PocTree/PocTree.services:jkl</name>
    <LOCK_STATUS>3</LOCK_STATUS>
    <type>
      <svc_type>xsltservice</svc_type>
      <svc_subtype>unknown</svc_subtype>
    </type>
    <path>/Flow Path;1.0/INVOKE;2</path>
    <isPub>false</isPub>
    <isNotification>false</isNotification>
    <isFlowServiceDisabled>false</isFlowServiceDisabled>
    <status>resolved</status>
  </reference>
  <reference>
    <name>WmPublic/pub.xml:xmlStringToXMLNode</name>
    <LOCK_STATUS>2</LOCK_STATUS>
    <type>
      <svc_type>java</svc_type>
      <svc_subtype>unknown</svc_subtype>
    </type>
    <path>/Flow Path;1.0/INVOKE;3</path>
    <isPub>false</isPub>
    <isNotification>false</isNotification>
    <isFlowServiceDisabled>false</isFlowServiceDisabled>
    <status>resolved</status>
  </reference>
  <reference>
    <name>WmPublic/pub.xml:xmlNodeToDocument</name>
    <LOCK_STATUS>2</LOCK_STATUS>
    <type>
      <svc_type>java</svc_type>
      <svc_subtype>unknown</svc_subtype>
    </type>
    <path>/Flow Path;1.0/INVOKE;4</path>
    <isPub>false</isPub>
    <isNotification>false</isNotification>
    <isFlowServiceDisabled>false</isFlowServiceDisabled>
    <status>resolved</status>
  </reference>
  <reference>
    <name>PocTree/PocTree.services:ghi</name>
    <LOCK_STATUS>4</LOCK_STATUS>
    <type>
      <svc_type>xsltservice</svc_type>
      <svc_subtype>unknown</svc_subtype>
    </type>
    <path>/Flow Path;1.0/INVOKE;5</path>
    <isPub>false</isPub>
    <isNotification>false</isNotification>
    <isFlowServiceDisabled>false</isFlowServiceDisabled>
    <status>resolved</status>
  </reference>
  <reference>
    <name>WxPackageTree/WxPackageTree.doc:NodeInfo</name>
    <LOCK_STATUS>2</LOCK_STATUS>
    <type>
      <type_name>record</type_name>
    </type>
    <path>/Service Path;1.0/signature;2;subPath;"/nodes;4;0;WxPackageTree.doc:NodeInfo"</path>
    <isPub>false</isPub>
    <isNotification>false</isNotification>
    <isFlowServiceDisabled>false</isFlowServiceDisabled>
    <status>reference</status>
    <reference>
      <name>WxPackageTree/WxPackageTree.doc:NodeInfo</name>
      <LOCK_STATUS>2</LOCK_STATUS>
      <type>
        <type_name>record</type_name>
      </type>
      <path>/children;4;1;WxPackageTree.doc:NodeInfo</path>
      <isPub>false</isPub>
      <isNotification>false</isNotification>
      <isFlowServiceDisabled>false</isFlowServiceDisabled>
      <status>recursive</status>
    </reference>
    <reference>
    <name>PocTree/PocTree.docs:nodeInfo</name>
    <LOCK_STATUS>4</LOCK_STATUS>
    <type>
      <type_name>record</type_name>
    </type>
    <path>/Flow Path;1.0/MAP;6/MAPCOPY;1/to_field;-2;subPath;"/nodeInfo;4;0;PocTree.docs:nodeInfo"</path>
    <path>/Flow Path;1.0/MAP;6/MAPCOPY;2/to_field;-2;subPath;"/nodeInfo;4;0;PocTree.docs:nodeInfo"</path>
    <path>/Flow Path;1.0/MAP;6/MAPCOPY;3/to_field;-2;subPath;"/nodeInfo;4;0;PocTree.docs:nodeInfo"</path>
    <isPub>false</isPub>
    <isNotification>false</isNotification>
    <isFlowServiceDisabled>false</isFlowServiceDisabled>
    <status>reference</status>
    <reference>
      <name>PocTree/PocTree.docs:nodeInfo</name>
      <LOCK_STATUS>4</LOCK_STATUS>
      <type>
        <type_name>record</type_name>
      </type>
      <path>/children;4;1;PocTree.docs:nodeInfo</path>
      <isPub>false</isPub>
      <isNotification>false</isNotification>
      <isFlowServiceDisabled>false</isFlowServiceDisabled>
      <status>recursive</status>
    </reference>
  </reference>
  </reference>
</referenced> 

预期输出xml

<?xml version="1.0"?>
<nodeInfo>
  <name>PocTree/PocTree.services:getReferencesForServices</name>
  <LOCK_STATUS>3</LOCK_STATUS>
  <type>
    <svc_type>flow</svc_type>
    <svc_subtype>default</svc_subtype>
  </type>
  <path/>
  <isPub>false</isPub>
  <isNotification>false</isNotification>
  <isFlowServiceDisabled>false</isFlowServiceDisabled>
  <status>reference</status>
  <children>
    <name>WmRoot/wm.server.ns.dependency:getReferenced</name>
    <LOCK_STATUS>2</LOCK_STATUS>
    <type>
      <svc_type>java</svc_type>
      <svc_subtype>unknown</svc_subtype>
    </type>
    <path>/Flow Path;1.0/INVOKE;0</path>
    <isPub>false</isPub>
    <isNotification>false</isNotification>
    <isFlowServiceDisabled>false</isFlowServiceDisabled>
    <status>resolved</status>
  </children>
  <children>
    <name>WmPublic/pub.xml:documentToXMLString</name>
    <LOCK_STATUS>2</LOCK_STATUS>
    <type>
      <svc_type>java</svc_type>
      <svc_subtype>unknown</svc_subtype>
    </type>
    <path>/Flow Path;1.0/INVOKE;1</path>
    <isPub>false</isPub>
    <isNotification>false</isNotification>
    <isFlowServiceDisabled>false</isFlowServiceDisabled>
    <status>resolved</status>
  </reference>
  <children>
    <name>PocTree/PocTree.services:jkl</name>
    <LOCK_STATUS>3</LOCK_STATUS>
    <type>
      <svc_type>xsltservice</svc_type>
      <svc_subtype>unknown</svc_subtype>
    </type>
    <path>/Flow Path;1.0/INVOKE;2</path>
    <isPub>false</isPub>
    <isNotification>false</isNotification>
    <isFlowServiceDisabled>false</isFlowServiceDisabled>
    <status>resolved</status>
  </children>
  <children>
    <name>WmPublic/pub.xml:xmlStringToXMLNode</name>
    <LOCK_STATUS>2</LOCK_STATUS>
    <type>
      <svc_type>java</svc_type>
      <svc_subtype>unknown</svc_subtype>
    </type>
    <path>/Flow Path;1.0/INVOKE;3</path>
    <isPub>false</isPub>
    <isNotification>false</isNotification>
    <isFlowServiceDisabled>false</isFlowServiceDisabled>
    <status>resolved</status>
  </children>
  <children>
    <name>WmPublic/pub.xml:xmlNodeToDocument</name>
    <LOCK_STATUS>2</LOCK_STATUS>
    <type>
      <svc_type>java</svc_type>
      <svc_subtype>unknown</svc_subtype>
    </type>
    <path>/Flow Path;1.0/INVOKE;4</path>
    <isPub>false</isPub>
    <isNotification>false</isNotification>
    <isFlowServiceDisabled>false</isFlowServiceDisabled>
    <status>resolved</status>
  </children>
  <children>
    <name>PocTree/PocTree.services:ghi</name>
    <LOCK_STATUS>4</LOCK_STATUS>
    <type>
      <svc_type>xsltservice</svc_type>
      <svc_subtype>unknown</svc_subtype>
    </type>
    <path>/Flow Path;1.0/INVOKE;5</path>
    <isPub>false</isPub>
    <isNotification>false</isNotification>
    <isFlowServiceDisabled>false</isFlowServiceDisabled>
    <status>resolved</status>
  </children>
  <children>
    <name>WxPackageTree/WxPackageTree.doc:NodeInfo</name>
    <LOCK_STATUS>2</LOCK_STATUS>
    <type>
      <type_name>record</type_name>
    </type>
    <path>/Service Path;1.0/signature;2;subPath;"/nodes;4;0;WxPackageTree.doc:NodeInfo"</path>
    <isPub>false</isPub>
    <isNotification>false</isNotification>
    <isFlowServiceDisabled>false</isFlowServiceDisabled>
    <status>reference</status>
    <children>
      <name>WxPackageTree/WxPackageTree.doc:NodeInfo</name>
      <LOCK_STATUS>2</LOCK_STATUS>
      <type>
        <type_name>record</type_name>
      </type>
      <path>/children;4;1;WxPackageTree.doc:NodeInfo</path>
      <isPub>false</isPub>
      <isNotification>false</isNotification>
      <isFlowServiceDisabled>false</isFlowServiceDisabled>
      <status>recursive</status>
    </children>
    <children>
    <name>PocTree/PocTree.docs:nodeInfo</name>
    <LOCK_STATUS>4</LOCK_STATUS>
    <type>
      <type_name>record</type_name>
    </type>
    <path>/Flow Path;1.0/MAP;6/MAPCOPY;1/to_field;-2;subPath;"/nodeInfo;4;0;PocTree.docs:nodeInfo"</path>
    <path>/Flow Path;1.0/MAP;6/MAPCOPY;2/to_field;-2;subPath;"/nodeInfo;4;0;PocTree.docs:nodeInfo"</path>
    <path>/Flow Path;1.0/MAP;6/MAPCOPY;3/to_field;-2;subPath;"/nodeInfo;4;0;PocTree.docs:nodeInfo"</path>
    <isPub>false</isPub>
    <isNotification>false</isNotification>
    <isFlowServiceDisabled>false</isFlowServiceDisabled>
    <status>reference</status>
    <children>
      <name>PocTree/PocTree.docs:nodeInfo</name>
      <LOCK_STATUS>4</LOCK_STATUS>
      <type>
        <type_name>record</type_name>
      </type>
      <path>/children;4;1;PocTree.docs:nodeInfo</path>
      <isPub>false</isPub>
      <isNotification>false</isNotification>
      <isFlowServiceDisabled>false</isFlowServiceDisabled>
      <status>recursive</status>
    </children>
  </children>
  </children>
</nodeInfo>

编写XSLT以获得预期的输出

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

    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="referenced">
        <nodeInfo>
            <xsl:apply-templates />
        </nodeInfo>
    </xsl:template>

    <xsl:template match="reference">
        <children>
            <xsl:apply-templates />
        </children>
    </xsl:template>
</xsl:stylesheet>

简化所有已完成的操作是重命名引用到nodeInfo,并引用子项。

然而,我无法得到确切的结构。感谢您对此主题的帮助。

此致 Nischal

0 个答案:

没有答案