嗨夥計, 我有這個相當笨拙的xslt,我用它將SOAPUI測試用例轉換爲更易讀的格式。目前,它使用以下使用位置計數節點 - 有時枚舉從0開始而不是1
<xsl:value-of select="position()-3"/>
我的問題有時測試用例枚舉從0開始,有時是從1開始。我不明白爲什麼會這樣列舉了測試用例?這與位置選擇器的實現方式有關嗎?有沒有更好的方法來計算節點的實例?
非常感謝,
理查德
以下是全部的代碼 - SANS造型。
`
<!-- Edited by XMLSpy® -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:con="http://eviware.com/soapui/config">
<xsl:output method="html" encoding ="utf-8"/>
<xsl:template match="/">
<html>
<head>
<script type="text/javascript">
function toggleDiv(divid){
var ele = document.getElementById(divid);
if(ele.style.display == 'none')
{
ele.style.display = 'block';
}
else
{
ele.style.display = 'none';
}
}
</script>
<style type="text/css"></style>
</head>
<body>
<xsl:apply-templates/>
<div class="help">This report is generated automatically by a scheduled job running on Richard Fortune's machine. The SOAPUI project files it references are located in sourcecontrol SVN (https://svn.xxx.xxxxxx.com/svn/network/TEST). These reports are generated daily as the projects they reference are subject to change.</div>
</body>
</html>
</xsl:template>
<xsl:template match="con:soapui-project">
<div><h1>Project Name : <xsl:value-of select="@name"/></h1></div>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="con:testSuite">
<xsl:if test="con:description=''">
<p class="warn"> (RICHARD - PLEASE PROVIDE A DESCRIPTION!!)</p>
</xsl:if>
<div id="content" onmousedown="toggleDiv('{position()}');"><h2 class="ex">TestSuite: <xsl:value-of select="@name"/></h2></div>
<br>
<p class="descSuite"><b>Suite Description: </b><xsl:value-of select="con:description"/></p>
</br>
<div style="display:none" id="{position()}"><xsl:apply-templates />
</div>
</xsl:template>
<xsl:template match="con:testCase">
<ul>
<li class="tc"><b>
(#<xsl:value-of select="position()-3"/>) Testcase: </b><xsl:value-of select="@name"/>
</li>
<xsl:if test="con:description=''">
<p class="warn">(Gentle reminder Richard - PLEASE PROVIDE A DESCRIPTION!!)</p>
</xsl:if>
<p class="descTc">
<strong><i>Description:</i></strong> <xsl:value-of select="con:description"/>
</p>
<ol class="step">
<xsl:for-each select="con:testStep"><li>TestStep: <xsl:value-of select="@name"/> </li></xsl:for-each>
</ol>
</ul>
<xsl:apply-templates />
</xsl:template>
<xsl:template match="*"></xsl:template>
</xsl:stylesheet>
`
這將是有用的你的XML輸入樣本。 – 2011-05-17 06:47:41
請編輯你的問題並提供一個完整的(但儘可能短)的XML文檔。同時提供你得到的錯誤結果並解釋應該是什麼結果。我想我知道問題可能是什麼,但我不想花時間去猜測。 – 2011-05-17 13:08:00