답변:
<xsl:if test="xpath-expression">...</xsl:if>
예를 들어
<xsl:if test="/html/body">body node exists</xsl:if>
<xsl:if test="not(/html/body)">body node missing</xsl:if>
html/body and not(html/body/node()).
다음 표현을 시도하십시오. boolean(path-to-node)
Patrick은의 사용 xsl:if과 노드의 존재를 확인하기위한 구문에서 모두 정확 합니다. 그러나 Patrick의 응답에서 알 수 있듯이 if-then-else와 동등한 xsl은 없으므로 if-then-else와 유사한 것을 찾고 있다면 일반적으로 xsl:chooseand를 사용하는 것이 좋습니다 xsl:otherwise. 따라서 Patrick의 예제 구문이 작동하지만 이는 대안입니다.
<xsl:choose>
<xsl:when test="/html/body">body node exists</xsl:when>
<xsl:otherwise>body node missing</xsl:otherwise>
</xsl:choose>
if-then-else, if-else if-else어떻습니까? davenpcj의 답변 test="somexpath"에서 두 번째로 만들 수 if-else if-else있습니까?
선택을 사용하는 것이 더 좋을 수도 있고, 식을 두 번 이상 입력하거나 잘못 입력 할 필요가 없으며, 다른 동작을 따를 수도 있습니다.
count(/html/body) = 0특정 수의 노드가 세트보다 더 흥미 롭기 때문에 매우 자주 사용 합니다. 예를 들어 ... 예기치 않은 표현식과 일치하는 노드가 두 개 이상인 경우.
<xsl:choose>
<xsl:when test="/html/body">
<!-- Found the node(s) -->
</xsl:when>
<!-- more xsl:when here, if needed -->
<xsl:otherwise>
<!-- No node exists -->
</xsl:otherwise>
</xsl:choose>
count(/html/body) = 0 천재! : DI 언제 (또는 무엇이든) /html[count(/body)=0]/someNodesomeNode/body
/html[count(/body)=0]은 아무것도 선택하지 않으며 XML에는 두 개의 루트 노드가있을 수 없습니다. 어쩌면 당신은 의미 /html[count(body)=0]와 동일 할 것이다, /html[not(body)]또는 /html[not(exists(body))].