「スイッチ」のような条件ステートメントを作成しようとしているのでtype
、XML ファイルの属性の値に応じて、HTML に特定のアイコンを配置してから、テキストを追加します。しかし、完全に機能していない場合...または私が望むとおりではありません。
XML:
<?xml version="1.0" encoding="utf-8"?>
<TreeView>
<Parent text="Installation">
<child text="Startup" type="video" file="startup.wmv" icon="c://user/desktop/blahblah.jpg"/>
<child text="Getting there" type="video" file="gettingthere.wmv" icontPath="something"/>
<child text="Steps" type="document" file="steps.docx" icon="asd"/>
<child text="Pictures" type="presentation" file="pics.jpg" icon="dasdasdas"/>
</Parent>
<Parent text="Usage">
<child text="Tilbud pane" type="video" file="tilbud.mwv" icon="asdasd"/>
<child text="Report pane" type="document" file="report.docx" icon="gfdhd"/>
</Parent>
</TreeView>
XSLT:
<?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="utf-8"/>
<xsl:template match="/">
<ul id="LinkedList1" class="LinkedList">
<xsl:apply-templates/>
</ul>
</xsl:template>
<xsl:template match="Parent">
<li>
<xsl:value-of select="@text"/>
<br/>
<ul>
<xsl:choose>
<xsl:when test="child/@type = 'video'">
<img src="play_icon.png" alt="play_video_icon" title="Video tutorial" />
</xsl:when>
<xsl:when test="child/@type = 'document'">
<img src="word_icon.png" alt="text_document_icon" title="Text Document" />
</xsl:when>
<xsl:when test="child/@type = 'presentation'">
<img src="powerpoint_icon.png" alt="powerpoint_icon" title="Power Point presentation" />
</xsl:when>
</xsl:choose>
<xsl:apply-templates select="child"/>
</ul>
</li>
</xsl:template>
<xsl:template match="child">
<li><xsl:value-of select="@text"/></li>
</xsl:template>
</xsl:stylesheet>
これは私が得るものです - >
![Not correct.][1]
------------------------------------
そして、これが私が望む方法です->
![Correct.][2]
------------------------------------
条件文を正しく並べていないと思いますが、どうすればいいのかわかりません。それで、これを修正する方法はありますか?