2013-03-18 4 views
1

속성 값 'cd'로 노드 'productgroep'을 선택하려고합니다. 이것은 작동하지 않고 실제로 이유를 이해하지 못합니다. 답변을 검색했지만 찾지 못했습니다.조건부로 노드가 작동하지 않습니다.

<?xml version="1.0" encoding="UTF-8"?> 
<?xml-stylesheet type="text/xsl" href="Oefening_8.xsl"?> 
<catalogus> 
<!-- cd catalogus --> 
<productgroep type="cd"> 
    <item referentienummer="7051444" catalogusnummer="1800022" EAN="0025218000222"> 
    ... 
</productgroep> 
<productgroep type="film"> 
    <item referentienummer="8051445" catalogusnummer="2800023" EAN="5051888073650"> 
    .... 
</productgroep> 
</catalogus 

XSL : 스타일 시트는 현재 무효이며, 아마도 당신은 XML 및 XSL을 사용하는 방법에 따라, 어딘가에서 오류를주고, 그래서

<?xml version="1.0" encoding="UTF-8"?> 

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 
<xsl:output method="html"/> 
<xsl:template match="/"> 
    <html> 
     <head> 
      <title>Oefening_8.xsl</title> 
      <meta charset="utf-8"/> 
      <link href="Oefening_8.css" type="text/css" rel="stylesheet"/> 
     </head> 
     <body> 
      <h1></h1> 
       <xsl:template match="productgroep[@type='cd']"> 
       </xsl:template> 
     </body> 
    </html> 
</xsl:template> 
</xsl:stylesheet> 

답변

0

<xsl:template/>이하는 <xsl:template/>의 자식이 될 수 없습니다.

하나의 해결 방법은 <xsl:template>을 별도로 만들고 <xsl:apply-templates />을 사용하여 원본 요소의 하위를 처리하는 것입니다.

<xsl:template match="/"> 
    <html> 
     <head> 
      <title>Oefening_8.xsl</title> 
      <meta charset="utf-8"/> 
      <link href="Oefening_8.css" type="text/css" rel="stylesheet"/> 
     </head> 
     <body> 
      <h1></h1> 
      <xsl:apply-templates /> 
     </body> 
    </html> 
</xsl:template> 

<xsl:template match="productgroep[@type='cd']"> 
    <xsl:value-of select="item/@catalogusnummer"/> <!-- print @catalogusnummer for example --> 
</xsl:template> 
0

@andyb는 지적했듯이 템플릿 안에 템플릿을 넣을 수 없습니다. xsl:template이있는 곳에서 xsl:apply-templates을 사용하려고했으나 현재 컨텍스트에 노드 catalogus 이상이므로 사용 된 경로로는 작동하지 않았을 수도 있습니다. 옵션은 다음과 루트 요소를 선택하는 초기 xsl:template을 변경할 수 있습니다 중 하나

또는

또는 xsl:apply-templates에 전체 경로 사용하기 :

첫 번째 옵션을 선호합니다 :

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 
<xsl:output method="html"/> 
<xsl:template match="/*"> 
    <html> 
     <head> 
      <title>Oefening_8.xsl</title> 
      <meta charset="utf-8"/> 
      <link href="Oefening_8.css" type="text/css" rel="stylesheet"/> 
     </head> 
     <body> 
      <h1></h1> 
      <xsl:apply-templates select="productgroep[@type='cd']" /> 
     </body> 
    </html> 
</xsl:template> 
</xsl:stylesheet> 
관련 문제