XSL内に含まれるXSL
XML / XSLがdomianで変換した場合、我々は(再利用可能ななされる)ライブラリ項目を使用する動的なコードのピースはしたい時があります。 私が意味するものは、おそらくこの例のシナリオをより明確にすることができます。
あなたのウェブサイト(および、XML、XSL transfroms ofcourseのを使用)を作成しており、ページのほとんどはコメントモジュールを持っているでしょう想像してみてください。 よく! あなたはすべてのページテンプレート(私が言うが、メンテナンスや手直し悪夢作る持っていけない)、または、より良いにこのコードをコピーしたり貼り付けか、あなたがあなたのページにそれを望むどこまででプルアップすることがINCLUDEファイルを作成します( S)...
では、どのようにXSL INCLUDEファイルを作成し、別のXSLファイルの内部に含まれていますか ? ここでどのようには...
物事を明確にするため...ここにあなたが作成したファイルの簡単なリストは...ここで、我々は、食品と呼ばれる親ページに果物や野菜についての情報を含むでしょう。
1。 food.xml - 変換が適用される上のXMLデータファイル
2。 food.xsl - 私たちのfood.xmlを変えていく主なXSLファイル、
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>










































