2016-11-02 4 views
0

나는 XML 아래에 있고 나는 다음과 같이 서브 노드가 최상위 노드로 언급 한 입력 XML에 XSLTXSLT는

를 사용하여 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>flow</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>java</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>java</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>xsltservice</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>java</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>java</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>xsltservice</type> 
     <path>/Flow Path;1.0/INVOKE;5</path> 
     <isPub>false</isPub> 
     <isNotification>false</isNotification> 
     <isFlowServiceDisabled>false</isFlowServiceDisabled> 
     <status>resolved</status> 
     </children> 
    </nodeInfo> 

그러나 예상 출력 XML을받을 수있는 기준은 그 오의 가치에서이다 언젠가 별도의 태그를 가지고이 부분

<type> 
     <svc_type>flow</svc_type> 
     <svc_subtype>default</svc_subtype> 
     </type> 

에게 있습니다 입력 XML의 하위 노드의 NE이 의미는, 자식 노드 또는 단지 하나를 가질 수있다.

<type> 
    <type_name>record</type_name> 
    </type> 

이제 예상 출력 XML은 <svc_type>는 '흐름'또는 '자바 서비스'또는 'xsltservice'의 값을 갖는 경우 입력 XML에서 만 <refrence> 태그를 선택하고 <type_name>을 가지고 그 <refrence> 태그를 생략하는 등의 방법으로 설계되어야한다 모든 값이있는 <type> 상위 노드에 속합니다.

또한 <svc_type>의 콘텐츠는 하위 노드는 부모 노드 용 <type> <svc_type><svc_subtype> 없어야 <type> 출력 XML의 값에 맵핑한다.

이 주제에 대한 도움을주십시오. 입력 XML 필터링을 달성하기 위해 작성된 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[type/svc_type[contains(., 'flow') or contains(., 'java') or contains(., 'xsltservice')]]) and (reference[type/type_name[not(contains(.,'record'))]])"> 
     <children> 
      <xsl:apply-templates /> 
     </children> 
    </xsl:template> 
</xsl:stylesheet> 

그래도이 부분은 커버하지 않는 XSLT 위 - <svc_type>이 하위 노드 <svc_type><svc_subtype> 없어야 <type> 및 XML 출력 값에 매핑되어야한다 상위 노드의 경우 <type>.

+0

지금까지 어떤 시도를하셨습니까? 코드 게시! 네가 그것을 달렸을 때 무슨 일이 일어난거야? 대신에 당신은 무엇을 기대 했습니까? 특별히 문제가있는 것은 무엇입니까? https://stackoverflow.com/help/mcve – Robert

+0

@ 로버트 - 질문 끝 부분에 xslt 부분을 추가했습니다. 좀 봐 주시겠습니까? 출력에 대해서는 부모 노드에 속한 태그가있는 모든 값을 더하거나 필터링 할 수 없습니다. 은 값에 매핑해야하고 출력 XML에는 하위 노드 을 포함하면 안됩니다. 부모 노드의 경우 Nis

답변

0

논리를 뒤집어 야합니다. 복사하려는 노드를 생각하는 대신, 복사하지 않으려는 대상에 대해 생각하고 이에 맞게 템플릿을 작성하고 무시해야합니다.

그러면 ID 템플릿이 복사하려는 모든 항목을 처리합니다.

입력 xml의 <reference> 태그를 포함하려는 경우 <svc_type>의 값은 'flow'또는 'javaservice'또는 'xsltservice'입니다.즉 직선 - 수행 할 수 있도록

<xsl:template match="reference[type/svc_type[not(contains(., 'flow') or contains(., 'java') or contains(., 'xsltservice'))]]" /> 

당신 다른 규칙이 이미 제거에 대한 하나입니다 이것의 반대는 그 세 값 중 하나에 <svc_type> 설정되어 있지 않는 등 <reference>을 제외 할 것입니다 전방 당신이 템플릿

,369 사이에 충돌이있을 수 있는데,이 경우에 모두 type/type_nametype/svc_type을 가진 reference 태그를 가질 수없는 한 우선 순위가 아마 여기에 필요하지 않습니다

<xsl:template match="reference[type/type_name]" priority="2" /> 

어떤 논리 반전없이

svc_type 단지 type에 당신 변환을 처리하기 위해 설정하는 또한 템플릿의 추가 참고이 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:template match="type[svc_type]"> 
     <type> 
      <xsl:value-of select="svc_type" /> 
     </type> 
    </xsl:template> 

    <xsl:template match="reference[type/svc_type[not(contains(., 'flow') or contains(., 'java') or contains(., 'xsltservice'))]]" /> 

    <xsl:template match="reference[type/type_name]" priority="2" /> 
</xsl:stylesheet> 

을보십시오.

+0

이것은 정상적으로 작동합니다. 그럼 난 우선 순위 = "2"템플릿과 함께 일하는 하나의 쿼리를 어떻게해야합니까? – Nis

+0

여기서는 적용 할 수 없지만'reference_name' 요소에'type_name'과'svc_type'이 "flow"또는 "java"가 아닌 경우이 경우 두 템플릿 모두 일치합니다. 이는 XSLT에서 오류로 간주됩니다. 우선 순위 요소는 기본 우선 순위를 무시하고 충돌을 해결하는 데 필요합니다. –