나는 XSLT를 배우고 있으며 기존 XML 파일을 필터링하려고 연습하고 기본적으로 선택된 노드 만 트리를 복사합니다. 조건이 일치하면 'test'라는 하위 문자열이 있습니다.XSL에서 필터링하는 방법?
신원 패턴을 변형하여, 나는 다음 코드가 :
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="(node() | @*)[contains(name(.), 'test')]" />
<!-- Bonus Q: What would be happening behind the scenes when I put this code inside the copy element?
<xsl:value-of select="." /> -->
</xsl:copy>
</xsl:template>
지금이 나에게 다음과 같은 출력을 얻는다, 그러나
<head>
<testA> <testAChild /></testA> <!-- should be <testA> <testAChild> foo </testAChild></testA> -->
<testB /> <!-- should be <testB> bar </testB> -->
<Ctest /> <!-- should be <Ctest> foobar </Ctest> -->
<!-- should be <DontDeleteThis> <testD> 420 </testD></DontDeleteThis> -->
</head>
를,이 결과의 값을 가지고 있지 않습니다 나무. 또한 현재 노드가 거짓이지만 자식, 손주 또는 가능하면 그랜드 그랜드 자식이 기준을 통과 할 수있는 모든 경우를 검사하지 않습니다.
<head>
<testA>
<testAChild> foo </testAChild>
</testA>
<testB> bar </testB>
<Ctest> foobar </Ctest>
<DeleteThis> DELETED </DeleteThis>
<DontDeleteThis>
<testD> 420 </testD>
</DontDeleteThis>
</head>
XML 파일도 제공하십시오. – AntonH
@AntonH 질문을 편집하고 XML 스 니펫으로 업데이트했습니다. 나는 이런 종류의 문제에 대한 일반적인 해결책을 찾고있다. 그래서 다른 종류의 XML 구조에서도 사용할 수있을만큼 유연해야한다. – WCGPR0