2013-01-14 1 views
1

내가 가진 내가 templete입니다억제/속성 값을 기반으로 XML의 내용을 삭제

<xsl:template match="para[@type='new']"> 
</xsl:template> 
을 사용하여 다음을 수행 할 수있는 = '새로운'몸/파라/@ 유형을 억제 할

<xml> 
    <Text> 
     <body> 
     <para type="new"> This para needs to be suppress </para> 
     <para type="old"> This is an old para </para> 
     </body>  
    </Text>  
</xml> 

같은 XML

그런데 실제로 body가 다른 요소를 포함하지 않으면 para/@ type = 'new'라는 조건을 추가하여 전체 본문 요소를 제거해야한다고 말합니다.

그래서

<xml> 
    <Text> 
     <body> 
     <para type="new"> This para needs to be suppress </para> 
     </body>  
    </Text>  
</xml> 

<xml> 
    <Text> 
    </Text>  
</xml> 

<xml> 
    <Text> 
     <body> 
      <para type="new"> This para needs to be suppress </para> 
      <para type="old"> This is an old para </para> 
     </body>  
    </Text>  
</xml> 

가 반환해야합니다 반환해야

<xml> 
    <Text> 
     <body> 
     <para type="old"> This is an old para </para> 
     </body>  
    </Text>  
</xml> 

어떤 도움을하거나 작업을 수행하는 방법을 암시 ...

+0

body 요소에 대한 템플릿이 있으면 표시해 주시겠습니까? 너무 길지 않다면 전체 XSLT를 사용하십시오. – JLRishe

+0

또한 ** body 요소가 ** child 요소가 전혀없는 경우 어떻게됩니까? –

+0

본문에는 항상 0 또는 1 개의 "새로운"paras와 0 또는 1 개의 "old"paras가 있으며 그 밖의 것은 없습니까? – JLRishe

답변

2

방법에 대한 또 하나의 템플릿 : 여기

<xsl:template match="Text[count(body/*) = count(body/para[@type = 'new'])]" /> 
+0

Excelent Thanks Rishe ... 위 조건을 기반으로 텍스트 노드를 제거 할 수 있습니까? – atif

+0

너무 크지 않다면 전체 XSL을 보여줄 수 있습니까? 그렇지 않으면 정보에 입각 한 대답을하기가 어렵습니다. – JLRishe

+0

XSL에서이 두 규칙 만 있습니다. . Text 요소가 제거되도록 두 번째 템플리트를 "본문"대신 텍스트에 적용 할 수 있습니까? – atif

2

것은

<xsl:template match="body[para[@type='new']][not(*[2])]" /> 

즉,이 파라와 요소를 일치하는 또 다른 방법을이다 요소는 'new'유형이지만 두 번째 요소는 없습니다.