私はこのXMLを持っています:
<TreeView>
<Parent text="Installation">
<child company="all" text="Startup" type="video" file="startup.mp4"/>
<child company="all" text="Getting there" type="video" file="small.mp4"/>
<child company="all" text="Steps" type="pdf_document" file="test.pdf"/>
<child company="all" text="Pictures" type="presentation" file="pics.ppx"/>
</Parent>
<Parent text="Usage">
<child company="B" text="Tilbud pane" type="video" file="b1.mp4"/>
<child company="B" text="Report pane" type="pdf_document" file="b2.pdf"/>
<child company="N" text="Tilbud pane" type="video" file="n1.mp4"/>
<child company="N" text="Report pane" type="pdf_document" file="n2.pdf"/>
<child company="D" text="Tilbud pane" type="video" file="d1.mp4"/>
<child company="D" text="Report pane" type="pdf_document" file="d2.pdf"/>
</Parent>
</TreeView>
そして、これまでのところ、このXSLT :
<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:apply-templates select="child"/>
</ul>
</li>
</xsl:template>
<xsl:template match="child[@type='video']">
<li>
<a href="{@file}" class="video">
<img src="play_icon.png" alt="video" title="Video tutorial"/>
<xsl:text> </xsl:text>
<xsl:value-of select="@text"/>
</a>
</li>
</xsl:template>
<xsl:template match="child[@type='pdf_document']">
<li>
<a href="{@file}" class="pdfdoc">
<img src="pdf_icon.png" alt="pdfdoc" title="PDF Document"/>
<xsl:text> </xsl:text>
<xsl:value-of select="@text"/>
</a>
</li>
</xsl:template>
<xsl:template match="child[@type='presentation']">
<li><a href="{@file}" class="presentation">
<img src="powerpoint_icon.png" alt="presentation" title="Power Point presentation"/>
<xsl:text> </xsl:text>
<xsl:value-of select="@text"/>
</a>
</li>
</xsl:template>
</xsl:stylesheet>
意図したとおりに完全に機能していますが、変換にもう 1 つの機能を追加したいと考えています。company属性の値に応じて、要素全体を含めるか、スキップするかを指定します。
詳細: company属性値が「all」である子要素は、変換されたファイルに常に含まれている必要があります。その後、残りの子要素は、会社属性値「B」を持つ場合にのみグループ化する必要があります。次に、さまざまな会社用に 3 つの異なる XSL ファイルを作成します。したがって、今のところ 1 つの会社の XSL コードのみが必要です。
そのために何らかの条件付きステートメントまたはテンプレートを使用する必要があるかどうかはわかりません。XSLファイルがちょっと複雑になったので、バグがあります。
誰かが私の要件を既存のコードに追加できる場合、それは大歓迎です。