I'd like to parse a SOAPUI Project file and generate some documentation from the file. I've written an XSLT to parse the project (my plan being that I run a scheduled job using Msxsl to automatically generate the latest "documentation" for my smoke tests).
The problem >> my xml files will contain multiple projects and within those projects there are lists of test cases. I'd ideally like to wrap those test cases in a collapsible div so that the overall document is more readable. Currently my div is being created and I'm trying to give it a unique name using the position of the Testsuite node.
<?xml version="1.0" encoding="ISO-8859-1"?>
<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 language="javascript">
function toggleDiv(divid){
if(document.getElementById(divid).style.display == 'none')
{
document.getElementById(divid).style.display = 'block';
}
else
{
document.getElementById(divid).style.display = 'none';
}
}
</script>
<style type="text/css">
body {font-family:Arial,Helvetica; }
h1 {color:black;
font-size:0.975em;
}
h2.ex {color:black;
font-size:0.875em;
}
li.tc {
font-size:0.875em;
}
p.desc {
margin: 2%;
border: 1px dotted black;
font-size:0.775em;
line-height:90%
}
</style>
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="con:soapui-project">
<h1>
Project Name:<xsl:value-of select="@name"/>
</h1>
<br />
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="con:testSuite">
<hr></hr>
<a href="javascript:;" onmousedown="toggleDiv('<xsl:value-of select="position()"/>');">
<xsl:attribute name="onmousedown"><xsl:value-of select="position()"/></xsl:attribute>
<h2 class="ex">
TestSuite: <xsl:value-of select="@name"/>
</h2>
</a>
<br>
<p class="desc">
Description: <xsl:value-of select="con:description"/>
</p>
</br>
<br />
<div id="mydiv" style="display:none">
<xsl:apply-templates />
</div>
</xsl:template>
<xsl:template match="con:testCase">
<ul>
<li class="tc">
(#<xsl:value-of select="position()-3"/>) Testcase: <xsl:value-of select="@name"/>
</li>
<xsl:if test="con:description=''">
(RICHARD - PLEASE PROVIDE A DESCRIPTION!!)
</xsl:if>
<p class="desc">
Description: <xsl:value-of select="con:description"/>
</p>
</ul>
<xsl:apply-templates />
</xsl:template>
<xsl:template match="*"></xsl:template>
</xsl:stylesheet>
This currently fails because of a validation error when I try to put XSLT syntax into the Javascript. I feel like I'm close, but usual escape methods aren't working for me.
Can someone offer the final piece?
Cheers, - Richard
type="text/javascript". Strictly speaking it should beapplication/javascript, but that's not supported by some browsers.<a href="javascript:;" onmousedown="toggleDiv('<xsl:value-of select="position()"/>');">is not valid, you must escape<in attribute value. You could use an Attribute Value Template:<a href="javascript:;" onmousedown="toggleDiv('{position()}');">