2012-01-23 4 views
2

XSLT를 처음 사용했습니다. 내가 이해하지 못하는 블록 코드가 있습니다.이 XSLT 코드는 무엇을하고 있습니까?

다음 블록에서 '*','*[@class='vcard']''*[@class='fn']'은 무엇을 의미합니까?

<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" encoding="utf-8"/> <xsl:template match="/"> 
    <script type="text/javascript"> 
     <xsl:text><![CDATA[function show_hcard(info) { 
     win2 = window.open("about:blank", "HCARD", "width=300,height=200," +  "scrollbars=no menubar=no, status=no, toolbar=no, scrollbars=no"); 
     win2.document.write("<h1>HCARD</h1><hr/><p>" + info + "</p>"); win2.document.close(); 
    }]]></xsl:text> 
    </script> 
    <xsl:apply-templates/> </xsl:template> 

    <xsl:template match="*"> 
    <xsl:copy> 
     <xsl:copy-of select="@*"/> 
     <xsl:apply-templates/> 
    </xsl:copy> </xsl:template> 

    <xsl:template match="*[@class='vcard']"> 
    <xsl:apply-templates/> </xsl:template> 

    <xsl:template match="*[@class='fn']"> 
    <u> 
     <a> 
     <xsl:attribute name="onMouseDown"> 
      <xsl:text>show_hcard('</xsl:text> 
      <xsl:value-of select="text()"/> 
      <xsl:text>')</xsl:text> 
     </xsl:attribute> 
     <xsl:value-of select="text()"/> 
     </a> 
    </u> </xsl:template> </xsl:stylesheet> 

답변

2

* 일치하는 모든 요소들은 *[@class='vcard'] 패턴 vcardclass 특성을 가진 소자를 일치한다. 그로부터 *[@class='fn']의 의미를 알 수 있습니다 ;-)

here을 시작하는 것이 좋습니다.

+1

1로 마지막 규칙을 작성했을 것이다. –

2

귀하의 스타일 시트에는 4 가지 템플릿 규칙이 있습니다. 영어로이 규칙은 다음과 같습니다.

(a) 맨 위에서 시작 (일치 = "/"), 먼저 스크립트 요소를 출력 한 다음 입력에서 다음 레벨을 내림 (xsl : apply-templates) 처리합니다.

(b) 요소의 기본 규칙 (match = "*")은 원본과 동일한 이름과 속성을 가진 출력에 새 요소를 만들고 다음 레벨을 처리하여 내용을 구성하는 것입니다 입력.

(c) class = "vcard"속성을 가진 요소에 대한 규칙은 입력에서 다음 단계를 처리하는 것 외에는이 요소를 사용하지 않는 것입니다.

(d) class 속성 = "FN"인 요소에 대한 규칙은 출력

X는 원소의 텍스트 콘텐츠가 처리되는
<u><a onMouseDown="show_hcard('X')">X</a></u> 

이다.

경험이 많은 XSLT 사용자

표준에 연결하기위한

<xsl:template match="*[@class='fn']"> 
    <u> 
     <a onMouseDown="show_hcard('{.}')"> 
     <xsl:value-of select="."/> 
     </a> 
    </u> 
</xsl:template> 
관련 문제