주어진 XSL 및 XML에 대해 출력 행이 하나 밖에 없습니다. for-each
에는 두 개의 시퀀스가 있기 때문에 출력 2 라인이 필요합니까?
내가 무엇이 누락 되었습니까? 사용XSLT : <for-each>이 두 번 반복되지 않는 이유
XSL : 중고
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="2.0">
<xsl:output indent="yes" />
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:variable name="pat" as="item()*">
<xsl:sequence select="/myroot[1]/mychild[1]/test[1]/@testing"/>
<xsl:sequence select="/myroot[1]/mychild[2]/comment[1]"/>
</xsl:variable>
<xsl:for-each select="$pat">
<xsl:choose>
<xsl:when test=". instance of element()">
<xsl:text> Node: </xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>Atomic value: </xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="."/>
<xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
XML은 :
<?xml version="1.0" encoding="Windows-1252" standalone="no"?>
<myroot >
<mychild id="123">
<fruit>apple</fruit>
<test hello="world" testing="removed" brackets="angled" question="answers"/>
<comment>This is a comment</comment>
</mychild>
<mychild id="789">
<fruit>orange</fruit>
<test brackets="round" hello="greeting">
<number>111</number>
</test>
<!-- this is a test comment -->
<dates>
<modified>123</modified>
<created>880</created>
<accessed>44</accessed>
</dates>
</mychild>
<mychild id="456">
<fruit>banana</fruit>
<comment>This will be removed</comment>
</mychild>
</myroot>
출력은 다음과 같다. 내가받은 것은 단 한 줄뿐입니다.
두 번째 시퀀스에 아무 것도 표시되지 않는 이유는 무엇입니까?
<?xml version="1.0" encoding="UTF-8"?>
원자 값 :
내가
<?xml version="1.0" encoding="UTF-8"?>
원자 값 아래로 주어진 같은 것을 표시하기를 기대
을 제거 :노드를 제거 : 단지 거기이기 때문에이 코멘트
에 귀하의 질문은 중요한 태그를 누락되었습니다. ''와'instance of'를 사용하기 때문에 XSLT-2.0 태그를 추가했습니다. 이제 완전히 새로운 질문입니다. –
zx485