A
Andy Chambers
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?
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?