Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > namespace problem

Reply
Thread Tools

namespace problem

 
 
Andy Chambers
Guest
Posts: n/a
 
      02-11-2008
I'm trying to create a little test system for checking the content of
xml documents. I'd like to have files something like this....

<xunit fo="http://www.w3.org/1999/XSL/Format">
<test name="sample ok"
xpath="//foage-sequence[1]/@master-reference"
expected="A4-portrait"/>
<test name="sample fail"
xpath="/non/existent/path"
expected="sdlfd"/>
</xunit>

....then use xslt to run through each test and check whether the value
resulting from the xpath expression meets the value in the expected
attribute. I'm using the dyn:dynamic extension to dynamically
evaluate the xpath and that seems to be working fine. My problem
comes with namespaces. How can I get my stylesheet to know about any
namespaces one might include in the test file? Here's the snippet of
xslt that actually runs the test.

<xsl:template match="test">
<xsl:variable name="xpath" select="@xpath"/>
<xsl:variable name="actual" select="concat('',
dyn:evaluate($xpath))"/>
<xsl:variable name="expected" select="@expected"/>

<xsl:choose>
<xsl:when test="$actual != $expected">
<error test="{@name}"
expected="{$expected}"
actual="{$actual}"/>
</xsl:when>
<xsltherwise>
<ok test="{@name}"/>
</xsltherwise>
</xsl:choose>

</xsl:template>

If I add xmlns:fo="...." to the template, it works correctly. Is
there any way I can achieve this by extracting the namespace from the
xunit element and putting it into the template?

--
Andy
 
Reply With Quote
 
 
 
 
Richard Tobin
Guest
Posts: n/a
 
      02-11-2008
In article <24b560e1-d4c0-4116-8871->,
Andy Chambers <> wrote:
>I'm trying to create a little test system for checking the content of
>xml documents. I'd like to have files something like this....
>
><xunit fo="http://www.w3.org/1999/XSL/Format">


I assume this should be xmlns:fo=...

>I'm using the dyn:dynamic extension to dynamically
>evaluate the xpath and that seems to be working fine. My problem
>comes with namespaces.


It appears that dyn:evaluate() uses the namespaces in scope at the
point of the call, so there doesn't seem to be any way to set them.

I suggest instead writing a stylesheet that transforms your tests into
a stylesheet that executes them. That has the added advantage of not
needing dynamic evaluation at all.

-- Richard
--
:wq
 
Reply With Quote
 
 
 
 
Andy Chambers
Guest
Posts: n/a
 
      02-11-2008
On Feb 11, 1:54 pm, rich...@cogsci.ed.ac.uk (Richard Tobin) wrote:
> In article <24b560e1-d4c0-4116-8871-1fccf20e2...@e6g2000prf.googlegroups.com>,
> Andy Chambers <achambers.h...@googlemail.com> wrote:
>
> >I'm trying to create a little test system for checking the content of
> >xml documents. I'd like to have files something like this....

>
> ><xunit fo="http://www.w3.org/1999/XSL/Format">

>
> I assume this should be xmlns:fo=...


I suppose so.

> I suggest instead writing a stylesheet that transforms your tests into
> a stylesheet that executes them. That has the added advantage of not
> needing dynamic evaluation at all.


Yeah I thought that might be the case. Didn't think about the other
advantage though. Thanks.

--
Andy
 
Reply With Quote
 
Philippe Poulard
Guest
Posts: n/a
 
      02-11-2008
Andy Chambers a écrit :
> I'm trying to create a little test system for checking the content of


Why don't you try an existing one ?

Have a look here :
http://reflex.gforge.inria.fr/xunit.html

> xml documents. I'd like to have files something like this....
>
> <xunit fo="http://www.w3.org/1999/XSL/Format">
> <test name="sample ok"
> xpath="//foage-sequence[1]/@master-reference"
> expected="A4-portrait"/>
> <test name="sample fail"
> xpath="/non/existent/path"
> expected="sdlfd"/>
> </xunit>


<!--first, let's use a convenient root element
for importing the modules to use ; the last
namespace URI doesn't refer to a module,
it's the ns URI expected for accessing inside
the XSLFO document-->
<xcl:active-sheet
xmlnscl="http://ns.inria.org/active-tags/xcl"
xmlns:io="http://ns.inria.org/active-tags/io"
xmlnsunit="http://reflex.gforge.inria.fr/xunit.html"
xmlns:fo="http://www.w3.org/1999/XSL/Format">

<!--let's define our test case-->
<xunit:test-case name="test-case" label="My test case">
<!--parse the input XSLFO to test ;
it can be as well the output of an XSLT transformation
as a DOM tree or SAX events-->
<xclarse name="fo" source="file:///path/to/file.fo"/>
<!--assert that we have what is expected-->
<xunit:assert-string-equals result="A4-portrait" expected="{
string( $fo//foage-sequence[1]/@master-reference ) }"/>
<xunit:assert-string-equals result="an other value" expected="{
string( $fo//fo:an/fother/foath ) }"/>
</xunit:test-case>

<!--generate an XML report-->
<xunit:merge-reports name="Summary of XSLFO tests" source="{
io:file( '.' ) }"
output="{ io:file( 'my-error-report.xml' ) }"/>
<!--the last step could be transforming the XML report generated
in HTML ; if you want to use the stylesheet I used in the
XUnit tutorial, just let me know (I should add it to the
bundle in the next release of the engine)-->

</xcl:active-sheet>

If you already know XPath and XSLT, you should understand the above
script ; unlike XSLT it's a script that accept several instructions set,
like XSLT it's XPath centric ; there are other little variations, have a
look at the tutorials if you want to learn more

--
Cordialement,

///
(. .)
--------ooO--(_)--Ooo--------
| Philippe Poulard |
-----------------------------
http://reflex.gforge.inria.fr/
Have the RefleX !
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ERROR CS0234: The type or namespace name 'DataAccessHelper' does not exist in the namespace 'BCC' (are you missing an assembly reference?) li.eddie@gmail.com ASP .Net 0 01-06-2006 11:31 AM
[XML Schema] Including a schema document with absent target namespace to a schema with specified target namespace Stanimir Stamenkov XML 3 04-25-2005 09:59 AM
Reaching into the default namespace when using another namespace. Jason Heyes C++ 1 11-19-2004 02:36 AM
Namespace: Is it a scope or a namespace? Anonymous C++ 3 08-18-2003 01:31 PM
Help:Why can't I use namespace System.Web? It is said that this namespace doesn't exist. But it should exist. Èý¹â ASP .Net 1 07-29-2003 04:31 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57