我有以下XML的文件類型和使用XSLT模板我嘗試創建一個HTML的報告:XSLT刪除重複的兒童及父節點
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<testmodule >
<testgroup>
<testgroup>
<testcase >
<teststep result="pass">=>
<CRID Name="Cleese" CR-ID="CR#1234" TimeStamp="20150520 0122" Backcolor="White" />
</teststep>
<teststep result="pass">=>:
<CRID Name="Cleese" CR-ID="CR#123" TimeStamp="20150520 0122" Backcolor="White" />
</teststep>
<verdict time="" timestamp="" endtime="" endtimestamp="" result="pass" />
<ident>Testcase1</ident>
<CRID Name="Cleese" CR-ID="CR#123" TimeStamp="20150520 0123" Backcolor="White" />
</testcase>
<testcase >
<teststep result="pass">
<CRID Name="Cleese" CR-ID="CR#1234" TimeStamp="20150520 0123" Backcolor="White" />
</teststep>
<teststep result="pass">=>
<CRID Name="Cleese" CR-ID="CR#1234" TimeStamp="20150520 0123" Backcolor="White" />
</teststep>
<teststep result="pass">=>
<CRID Name="Cleese" CR-ID="CR#1234" TimeStamp="20150520 0122" Backcolor="White" />
</teststep>
<verdict result="pass" />
<ident>Testcase2</ident>
<CRID Name="Cleese" CR-ID="CR#1234" TimeStamp="20150520 0123" Backcolor="White" />
</testcase>
<testcase >
<testlogfile file="" />
<teststep result="pass">=> Result:
<CRID Name="Cleese" CR-ID="CR#123" TimeStamp="20150520 0123" Backcolor="White" />
</teststep>
<verdict result="pass" />
<ident>Testcase3</ident>
<CRID Name="Cleese" CR-ID="CR#1234" TimeStamp="20150520 0123" Backcolor="White" />
</testcase>
<title>1.3 Group</title>
</testgroup>
<title>1. Group</title>
</testgroup>
<verdict time="" timestamp="" endtime="" endtimestamp="" result="pass" />
<title>Testmodul</title>
</testmodule>
我想實現的是去除在html文件中具有CR-ID屬性的重複條目。我試圖使用「Muenchian方法」,但字面上失敗了。
所以我看到另一個代碼片段,並試圖適應它,但它不工作。它刪除所有重複項,但我只想刪除每個測試用例的重複項。 這裏是.xslt - 模板的一部分:
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
<xsl:template match="testcase" mode="overview">
<xsl:for-each select="descendant::CRID[not(@CR-ID=preceding::CRID/@CR-ID)]">
<xsl:if test="@CR-ID !=''">
<xsl:element name="br"/>
<xsl:value-of select="@CR-ID" />
</xsl:if>
</xsl:for-each>
</xsl:template>
我的問題是,屬性「CR-ID」可以如兒童中的「一步步測試」或「測試用例」中找到。所以一些條目被徹底刪除。
的希望輸出將只給我在我的HTML如下條目:
- 測試用例1:只有CR#1234,CR#123
- 測試用例2:只有CR#1234
- 測試用例3:僅CR#1234,CR#123
HTML代碼應該是這樣的:
<td>1.1.1</td>
<td >Testcase1</td>
<td ><br>CR#1234<br>CR#123</td>
<td>-</td>
</tr>
<tr>
<td >1.1.2</td>
<td >Testcase2</td>
<td ><br>CR#1234</td>
<td >-</td>
</tr>
<tr>
<td >1.1.3</td>
<td >Testcase3</td>
<td ><br>CR#1234<br>CR#123</td>
<td ">-</td>
從xml文件中使用「CR#1234」和「CR#123」。使用我發佈的xslt代碼只有testcase1獲得CR#,其他人是空白/空的。
任何人都可以幫助我嗎?
沒有很好地形成的輸入。請更正它併發布預期的輸出HTML代碼。 –
只是調整了代碼以更好地描述問題。 – Cleese
你在使用XSLT 1.0嗎? –