2

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

4
  • Minor aside, but the language for the script is usually specified with type="text/javascript". Strictly speaking it should be application/javascript, but that's not supported by some browsers. Commented Feb 28, 2011 at 9:44
  • 1
    Your stylesheet has some problems. But validation is the first: this start tag <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()}');"> Commented Feb 28, 2011 at 12:44
  • Good question, +1. See my answer that points out an obvious problem with your code and provides the standard solution. Commented Feb 28, 2011 at 13:55
  • Thanks Alejandro. Both yours and Dimitres responses fixed the issue. Commented Feb 28, 2011 at 22:23

3 Answers 3

3

One obvious problem:

  <a href="javascript:;"
  onmousedown="toggleDiv(<xsl:value-of select="position()"/>');"> 
<xsl:attribute name="onmousedown">
   <xsl:value-of select="position()"/>
  </xsl:attribute> 

Must be:

   <a href="javascript:;"/>

   <xsl:attribute name="onmousedown">
    <xsl:value-of select="position()"/>
   </xsl:attribute> 

The reason for this problem is that markup (elements) is not allowed as value of an attribute in any well-formed XML document.

Sign up to request clarification or add additional context in comments.

Comments

1

Use:

<![CDATA[
  javascript code here
]]>

Everything inside it is totally ignored by any self-respecting XML parser.

Comments

0

How about putting your JavaScript and CSS into external .js and .css files and using appropriate HTML tags to reference them?

1 Comment

For the purposes of this solution one single file works better than multiple files. This is meant to support a process and not exactly something I want to bloat out with extra files. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.