2017-09-05 8 views
0

사용자 정의 태그 또는 함수를 XSLT에 추가 할 수 있습니다. 다시 설명 드리겠습니다. include-html을 내 데모에 추가 할 수 있습니다 .을 찾을 때 XSLT에 로직을 추가 할 수 있습니다. 태그 값이있는 템플릿과 일치합니다 apply-template에서 수행) 값을 가져 와서 출력하십시오.xslt에서 맞춤 태그를 추가하는 방법은 무엇입니까?

여기 내 코드입니다. 내 예에서 http://xsltransform.net/6pS1zDt/1

<?xml version="1.0" encoding="UTF-8" ?> 
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> 
    <xsl:output method="html" doctype-public="XSLT-compat" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" /> 

    <xsl:template match="/"> 
     <hmtl> 
     <head> 
      <title>New Version!</title> 
     </head> 
     <include-html>a</include-html> 
     </hmtl> 
    </xsl:template> 

    <xsl:template match="a"> 
    <xsl:variable name="ab" select="'ss'"/> 
    <p><xsl:value-of select="$ab"/></p> 
</xsl:template> 
</xsl:transform> 

나는 당신이 이것을 달성 할 수

**<p>ss</p>** 
+0

ht에서 시작해야한다. tps : //www.w3schools.com/xml/xsl_intro.asp –

+0

@MatthewWhited 나는 이걸 알고있다. – naveen

답변

0

예상 출력을 템플릿과 일치 **<p>ss</p>**

<include-html>a</include-html> 

반환 include-html value.No의 a 값을 쓰고 있어요 어떤 종류의 메타 스타일 시트 (le t의 이름을에게 test.xslt) : 당신이 XSLT

xsl.sh test.xslt test.xslt 

같은 XML 입력으로하여 XSLT 프로세서에이를 전달하면

<?xml version="1.0" encoding="UTF-8" ?> 
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> 
    <xsl:output method="xml" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" /> 

    <!-- identity template --> 
    <xsl:template match="node()|@*"> 
     <xsl:copy> 
     <xsl:apply-templates select="node()|@*" /> 
     </xsl:copy> 
    </xsl:template> 

    <xsl:template match="/whatever"> 
     <hmtl> 
     <head> 
      <title>New Version!</title> 
     </head> 
     <include-html>a</include-html> 
     </hmtl> 
    </xsl:template> 

    <xsl:template match="include-html[text()='a']"> 
    <xsl:variable name="ab" select="'ss'"/> 
    <p><xsl:value-of select="$ab"/></p> 
    </xsl:template> 

</xsl:transform> 

출력이는

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> 
    <xsl:output method="xml" 
       omit-xml-declaration="yes" 
       encoding="UTF-8" 
       indent="yes"/> 

    <!-- identity template --> 
    <xsl:template match="node()|@*"> 
     <xsl:copy> 
     <xsl:apply-templates select="node()|@*"/> 
     </xsl:copy> 
    </xsl:template> 

    <xsl:template match="/whatever">  <!-- must NOT match --> 
     <hmtl> 
     <head> 
      <title>New Version!</title> 
     </head> 
     <p>ss</p>      <!-- REPLACED! --> 
     </hmtl> 
    </xsl:template> 

    <xsl:template match="include-html[text()='a']"> 
     <xsl:variable name="ab" select="'ss'"/> 
     <p> 
     <xsl:value-of select="$ab"/> 
     </p> 
    </xsl:template> 

</xsl:transform> 

가까이있는 니가 원한다면, 나는 ...