1
XSLT를 사용하여 조상 노드 이름을 인쇄하려고합니다.조상 이름을 선택하는 데 혼란이 있음
다음은 내 XSLT입니다.
<xsl:apply-templates select="(//title)[1]"/>
<xsl:template match="title">
<xsl:value-of select="name(ancestor::node())"/>
</xsl:template>
내 XML은 아래와 같습니다.
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
<!--ancestor-->
<cd>
<!--parent-->
<title name="titleName" property="propertyName">Empire Burlesque</title>
<!--self-->
<artist>Bob Dylan</artist>
<!--following-sibling-->
<country>USA</country>
<!--following-sibling-->
<company>Columbia</company>
<!--following-sibling-->
<price>10.90</price>
<!--following-sibling-->
<year>1985</year>
<!--following-sibling-->
</cd>
</catalog>
여기 아래 문장을 사용할 때. 나는 그것이 나에게 아래의 예외
XSLT 2.0 Debugging Error: Error: file:///C:/Users/u0138039/Desktop/Training%20Docs/XSLT%20Training/Sample.xsl:209: Wrong occurrence to match required sequence type - Details: - XPTY0004: The parameter value ('3' item(s)) at position '1' of the 'name' function has the wrong occurrence to match the sequence type node() ('zero or one')
을주고있다
<xsl:value-of select="name(ancestor::node())"/>
또는
<xsl:value-of select="name(ancestor::*)"/>
를 사용하는 다른
<xsl:value-of select="name(../..)"/>
하지만 사용할 때, 부모의 이름을 얻을 수 있습니다
<xsl:value-of select="name(parent::*)"/>
이 이유는 parent
에서 작동하지만 ancestor
에서는 작동하지 않는 이유를 알려주세요.
이것은 매우 혼란 스럽습니다. <xsl:value-of select="name(ancestor::node())"
같은 것을 사용하여 ancestor
이름을 얻으려면 어떻게해야합니까?
감사
조상의 이름은? 'title' 엘리먼트의 문맥에서'ancestor :: node()'를 사용하면,'cd' 엘리먼트와'catalog' 엘리먼트와 문서 노드를 모두 조상 (ancestor) 노드로 선택합니다. ' '은 조부모의 이름을 출력해야합니다. –