我有这个XML:条件XSLT转换
<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>
它可以正常使用,如预期,但我想补充一个功能的转变。我想要取决于公司属性的值,以包含整个元素,或者跳过它。
阐述:的子元素,其公司属性值“所有”,必须包含在转换文件。之后,子元素的其余部分只能在具有公司属性值“B”的情况下进行分组。然后,我将为不同的公司提供3个不同的XSL文件。所以我现在只需要一个公司的XSL代码。
我不确定我是否必须以某种方式使用条件语句或模板。我只是被窃听了,因为我的XSL文件对我来说变得有点复杂。
如果有人可以根据我的要求进行添加,现有的代码 - 将不胜感激。
你好Milknocookiez,您可以将XPATH添加到您的过滤元素:的 。这只会给你想要的子元素。但他们应该如何分组?你有没有看过?最好的问候,PETER –
Peter
@彼得 - 谢谢。他们应该像以前一样分组。我需要的唯一补充是区分* company *属性。所以如果属性是** all **或** B ** - 他们会被分组,其余的都会被跳过。 – Milkncookiez