XSL :XSLT 1.0 : 경기에만 우선 순위에 따라 두 개의 템플릿 중 하나
<xsl:template match="/">
<xsl:apply-templates select="*[local-name(.)='root']/*[local-name(.)='child1']" />
<xsl:apply-templates select="*[local-name(.)='root']/*[local-name(.)='child2']/*[local-name()='anotherchild1']" />
</xsl:template>
<xsl:template match="*[local-name(.)='child1']">
<!-- do something in template1 !-->
</xsl:template>
<xsl:template match="*[local-name(.)='anotherchild1']" priority="0">
<!-- do something in template2 !-->
</xsl:template>
예 :
<a:root>
<b:child1>
<d:grandchildOfChild1>
</d:grandchildOfChild1>
</b:child1>
<c:child2>
<d:anotherchild1>
<d:grandchildOfAnotherChild1>
</d:grandchildOfAnotherChild1>
</d:anotherchild1>
</c:child2>
</a:root>
요구 사항 :
- 전용 '자식 1'이 존재하는 경우, 'grandchildOfChild1'로 무언가하고 싶습니다.
- 'anotherchild1'만 있다면, 'grandchildOfAnotherChild1'을 사용하여 무언가를 할 수 없습니다.
- 'child1'& 'anotherchild1'이있는 경우, 'child1'템플릿 만 우선 적용하고 'grandchildOfChild1'로 무언가를하고 싶습니다.
위의 XSL은 # 1, # 2에 대한 예상 결과를 나타내지 만 두 가지 모두 존재하면 두 템플릿이 일치하고 두 결과가 모두 렌더링됩니다. 어떻게하면 첫 번째 걸릴 수 있을까요? 단지 '자식 1'이 존재하는 경우
나에게 질문은 분명하지 않다. 귀하의 의견에있는 모든 요소를 볼 수 있지만 귀하의 설명은 그들의 존재에 "조건부"입니다. 당신은 그것을 바꿔 말할 수 있습니까? –
이 문제를 해결하기 전에해야 할 일은 네임 스페이스를 올바르게 사용하는 법을 배우는 것입니다. 그렇게하는 방법을 보여주는 SO에는 여기에 수십 가지의 답이 있습니다. 나는 또한 당신의 질문이 완전히 불분명하다는 것에 동의합니다. 현실적인 예와 원하는 출력을 보여주십시오. – JLRishe