包括XSL内的XSL
如果XML / XSL转换是你的结构域,然后还有时候,我们需要一个动态代码peice要使用库项目(可重复使用的要作出)。 我的意思,可能与这个示例场景中更明确。
想象你正在创建一个网站(使用的XML,XSL transfroms当然)和大多数的网页将有一个评论模块 。 好吧! 然后,复制或粘贴此代码到每一页的模板(我不说,但维修和返工一场噩梦),甚至更好,你创建包含文件可以在任何你想它在您的网页拉( S)...
那么,如何创造一个XSL INCLUDE文件,它包括在另一个XSL文件 ? 这里是如何...
只是把事情说清楚......这里是快速的文件列表,您将创建......在这里,我们将纳入食品父页左右的水果和蔬菜的信息。
1。 food.xml - XML数据文件的转换将应用于
2。 food.xsl - 主要XSL文件,这将改变我们的food.xml
3。 inc_fruits.xsl - 的XSL包括会使水果的数据文件
4。 inc_vegtables.xsl - XSL的文件,将呈现vetetables数据
我不认为我有解释太多,以上元素的代码,将自明...
FOOD.XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="food.xsl"?>
<food>
<date>July 2008</date>
<description>All about things we eat everyday</description>
<fruits type="tropical">
<item name="mango" moreinfo="http://www.mango.com">Mango is the king of fruits</item>
<item name="banana" moreinfo="http://www.banana.com">Banana once a day , keeps the doctor away</item>
<item name="orange" moreinfo="http://www.orange.com">Orange is the color and rich in vitamin C</item>
<item name="Papaya" moreinfo="http://www.papaya.com">Papaya - Hot when raw, cold when ripe</item>
</fruits>
<vegetables>
<item name="spinach" moreinfo="http://www.spinach.com">Spinach is full of iron</item>
<item name="asparagus" moreinfo="http://www.asparagus.com">Asparagus contains loads of vitamin D </item>
<item name="fenugreek" moreinfo="http://www.fenugreek.com">Fenugreek is rich in vitamin C</item>
</vegetables>
</food>
FOOD.XSL
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:include href="inc_fruits.xsl" />
<xsl:include href="inc_vegetables.xsl" />
<xsl:template match="/">
<html>
<head>
<title>Title</title>
</head>
<body>
<h3><xsl:value-of select="/food/description" /></h3>
Modification Date : <xsl:value-of select="/food/date" />
<hr/>
<h5> About Fruits</h5>
<xsl:call-template name="about_fruits"/>
<hr/>
<h5> About Vegetables</h5>
<xsl:call-template name="about_vegetables"/><hr/>
</ BODY>
</ HTML>
</ XSL模板>
</ XSL样式表>
INC_FRUITS.XSL
<?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="iso-8859-1" />
<xsl:template name="about_fruits">
<xsl:for-each select="/food/fruits/item/@*">
attribute name : <xsl:value-of select="name()"/>
attribute value : <xsl:value-of select="."/> <br />
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
INC_VEGETABLES.XSL
<?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="iso-8859-1" />
<xsl:template name="about_vegetables">
<xsl:for-each select="/food/vegetables/item/@*">
attribute name : <xsl:value-of select="name()"/>
attribute value : <xsl:value-of select="."/> <br/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>










































