Hi,

We maintain a base set of XSLs for each client project (similar to Forrest). We
have a need to update or 'fix' XSL's.  This requires some functional testing. We
first transform to an XML document that describes the structure. Here is a
snippet of the XSLT:

<xsl:template match="xsl:stylesheet">

   <stylesheet id="basic_1col.xsl">

    <doc>A basic 1 column layout. This is a primary stylesheet. Each primary
stylesheet includes global_definitions.xsl, which in turn includes the common
XSL pages. Much of the layout can be affected just by changing the
/css/project.css. When a page is requested/generated, a source XML (always
/WEB-INF/styling/site.xml) is transformed against a primary XSL.</doc>

    <doc>global_definitions.xsl includes the common XSL templates, gathers
parameters sent in
from  the server and sets up common global variables.</doc>
      <xsl:choose>
         <xsl:when test="boolean(xsl:include[@href='global_definitions.xsl'])">

            <include href="global_definitions.xsl" present="true"/>

         </xsl:when>
         <xsl:otherwise>

            <include href="global_definitions.xsl" present="false"/>

         </xsl:otherwise>
      </xsl:choose>


      <doc>Depending on the value of this variable paths will be built starting
from root relative if true, or document relative if falses.</doc>
      <xsl:choose>
         <xsl:when test="boolean(xsl:variable[@name='root_relative'])">

            <variable name="root_relative" select="{xsl:variable/@select}"
present="true"/>

         </xsl:when>
         <xsl:otherwise>

            <variable name="root_relative" select="{xsl:variable/@select}"
present="false"/>

         </xsl:otherwise>
      </xsl:choose>

      <doc>match the document root to start setting up the HTML page
structure</doc>
      <xsl:choose>
         <xsl:when test="boolean(xsl:template[@match='/'])">


            <template match="/" present="true">


               <xsl:choose>
                  <xsl:when test="boolean(xsl:template/html)">

                     <html present="true">
                        <doc>call to head.xsl to set up the HTML HEAD</doc>
                        <xsl:choose>
                           <xsl:when
test="boolean(xsl:template/html/xsl:call-template[@name='head'])">

                              <call-template name="head" present="true"/>

                           </xsl:when>
                           <xsl:otherwise>

                              <call-template name="head" present="false"/>

                           </xsl:otherwise>
                        </xsl:choose>
........etc......
-------------------------------------

Then this output is transformed to a report and or used to update/fix existing
XSL

best,
-Rob



> -----Original Message-----
> From: Stephen Ng [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, August 29, 2002 6:49 AM
> To: [EMAIL PROTECTED]
> Subject: RE: Unit testing xslt
>
>
> I have unit tests for all my xslt.
>
> I'm not using XSLTUnit (which is a fine program)--in my case, for each
> xslt file, I have a one or more test input files and corresponding
> reference files which are the expected result when I run the transform.
> I use file names/extensions to group them:
>
> myScript.xslt
> myScript.simpleTest.xml
> myScript.simpleTest.ref
> myScript.complexTest.xml
> myScript.complexTest.ref
>
> I use a combination of batch jobs and ant scripts to match up the files,
> run the tests, and compare the results.
>
> I don't always do test-first--sometimes it's just easier to test your
> code inside your app.  So what I often do is write the code, test it in
> the app, and then write the tests.  I then back out my change, and run
> the tests again.  The tests should fail--if they don't, I've done
> something wrong in my test code.  I then reintroduce my changes one bit
> at a time, and make sure sure my tests start to succeed again.
>
> I think unit testing xslt's is a great thing.
>
> HTH,
>
> Steve
>
> > -----Original Message-----
> > From: Robert Leftwich [mailto:[EMAIL PROTECTED]]
> > Sent: Wednesday, August 28, 2002 9:58 PM
> > To: [EMAIL PROTECTED]
> > Subject: Unit testing xslt
> >
> >
> > Given Cocoon's big focus on transforms, I was wondering if
> > anyone is using
> > unit tests and/or test-first design when developing their xslt? I'd
> > appreciate any comments on its effectiveness and what tools
> > you are using
> > (XSLTunit for example?).
> >
> > Robert>



---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <[EMAIL PROTECTED]>
For additional commands, e-mail:   <[EMAIL PROTECTED]>

Reply via email to