>> English << | Français | Deutsch | Magyar | 中文 | Polski ZVON > Tutorials > XSLT Tutorial
>> Page 70 << | Prev | Next | Contents | Element Index

You can use xsl:apply-imports element to get information from an imported template, whose behaviour you are changing. XSLT stylesheet 2 imports XSLT stylesheet 1 and overrides its template. XSLT stylesheet 3 imports XSLT stylesheet 1 and changes its template. xsl-apply-imports works only for templates imported with xsl:import, not for templates included with xsl:include ( XSLT stylesheet 4 ).

XSLT stylesheet 1

XML Source
<source>

<AAA/>
<BBB/>
<CCC/>

</source>

Output
<DIV style="color:red">AAA</DIV>

<DIV style="color:red">BBB</DIV>

<DIV style="color:red">CCC</DIV>

HTML view
AAA
BBB
CCC
XSLT stylesheet (file: id2.xsl )
<xsl:stylesheet version = '1.0'
     xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

<xsl:template match="/*/*">
     <DIV style="color:red">
          <xsl:value-of select="name()"/>
     </DIV>
</xsl:template>


</xsl:stylesheet>


XSLT stylesheet 2

XML Source
<source>

<AAA/>
<BBB/>
<CCC/>

</source>

Output
<EM>AAA</EM>

<EM>BBB</EM>

<EM>CCC</EM>

HTML view
AAA BBB CCC
XSLT stylesheet (file: id3.xsl )
<xsl:stylesheet version = '1.0'
     xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

<xsl:import href="id2.xsl"/>
<xsl:template match="/*/*">
     <EM>
          <xsl:value-of select="name()"/>
     </EM>
</xsl:template>


</xsl:stylesheet>


XSLT stylesheet 3

XML Source
<source>

<AAA/>
<BBB/>
<CCC/>

</source>

Output
<EM>
  <DIV style="color:red">AAA</DIV>
</EM>

<EM>
  <DIV style="color:red">BBB</DIV>
</EM>

<EM>
  <DIV style="color:red">CCC</DIV>
</EM>

HTML view
AAA
BBB
CCC
XSLT stylesheet (file: id4.xsl )
<xsl:stylesheet version = '1.0'
     xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

<xsl:import href="id2.xsl"/>
<xsl:template match="/*/*">
     <EM>
          <xsl:apply-imports/>
     </EM>
</xsl:template>


</xsl:stylesheet>


XSLT stylesheet 4

XML Source
<source>

<AAA/>
<BBB/>
<CCC/>

</source>

Output
<EM/>

<EM/>

<EM/>

HTML view
XSLT stylesheet (file: id5.xsl )
<xsl:stylesheet version = '1.0'
     xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

<xsl:include href="id2.xsl"/>
<xsl:template match="/*/*">
     <EM>
          <xsl:apply-imports/>
     </EM>
</xsl:template>


</xsl:stylesheet>