2014-02-25 2 views
1

비슷한 코드가 여러 xslt 개 있습니다. 이 코드 중 일부와 함께 일반 파일을 만들고이 xslt에 포함하려고합니다. 예를 generic.xsl에 대한"추상"xsl 파일을 만들 수 있습니까

<xsl:template match="photos"> some general gode </xsl:template> 

specific.xsl

include|import generic.xsl 

<xsl:template match="photos"> 
Here I need to invoke code from generic.xsl 
and add some specific code 

</xsl:template> 

답변

-1

<xsl:import>을 사용하여 다른 파일에서 XSLT 템플릿을 가져올 수 있습니다. 이 템플릿이 내부 스타일 시트에 존재할 경우 외부 스타일 시트에 <xsl:template match="photos">을 정의 할 필요조차 없습니다.

마틴이 말한대로 <xsl:apply-imports>을 사용하여 가져온 스타일 시트를 호출 할 수 있습니다. 이는 가져온 템플릿이 주 템플릿보다 우선 순위가 낮기 때문입니다. 모두 우선 순위가 같기를 원하면 <xsl:include/>을 대신 사용할 수 있습니다.

<xsl:template name="process_photos"> 
    ... 
</xsl:template> 

을 그리고 <xsl:call-template>를 사용하여 호출

또는 당신 이름으로 템플릿을 정의 할 수 있습니다. 현재 컨텍스트는 호출 된 템플릿으로 전달됩니다.

<xsl:template match="photos"> 
    <xsl:call-template name="process_photos"/> 
</xsl:template> 
2

사용 <xsl:apply-imports/> 가져온 generic.xsl에서 템플릿 "호출"하는 : 또한 http://www.w3.org/TR/xslt#apply-imports

<xsl:template match="photos"> 
<xsl:apply-imports/> 
and add some specific code 

</xsl:template> 

참조 .

관련 문제