Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot test a named template with a particular context #66

Open
GoogleCodeExporter opened this issue Jun 8, 2015 · 7 comments
Open

Comments

@GoogleCodeExporter
Copy link

The source XSLT: 

<xsl:template name="copy-content">
  <xsl:copy-of select="."/>
</xsl:template>

The scenario: 

<x:scenario>
  <x:context select="//p">
    <sec>
      <p>text</p>
    </sec>
  </x:context>

  <x:call template="copy-content"/>

  <x:expect>
    <p>text</p>
  </x:expect>
</x:scenario>

The expected output is: 
<p>text</p>

But the error with the following message is thrown: "Variable $context has not 
been declared". When I look at the generated XSLT I find that the $context 
variable is generated in the default namespace, while it should be 
$impl:context:

<xsl:variable name="impl:context" select="$impl:context-doc/(//p)"/>

<xsl:for-each select="$context">
  <xsl:call-template name="copy-content"/>
</xsl:for-each>

The version of the product is: XSpec 0.4.0 Release Candidate 1.
The issue is not environment-dependent.

Original issue reported on code.google.com by [email protected] on 28 Feb 2014 at 12:56

@GoogleCodeExporter
Copy link
Author

+1, one of our users also stumbled upon this problem.

Original comment by [email protected] on 2 Sep 2014 at 6:08

@yamahito
Copy link

+1

@tgraham-antenna
Copy link
Member

A workaround may be to write a one-template 'runner' XSLT that imports the real stylesheet, where the single template matches on the right element and just calls the named template. The XSpec file uses the 'runner' stylesheet rather than the real stylesheet.

@yamahito
Copy link

I've tried working around it by passing the context as a tunnel parameter.  It's horrible, and you have to do everything within the template using $context explicitly.

On Thu, Sep 17, 2015 at 2:41 PM, Tony Graham [email protected]
wrote:

A workaround may be to write a one-template 'runner' XSLT that imports the real stylesheet, where the single template matches on the right element and just calls the named template. The XSpec file uses the 'runner' stylesheet rather than the real stylesheet.

Reply to this email directly or view it on GitHub:
#66 (comment)

@markdunnoup
Copy link

This is possibly a small error in the file xspec\src\compiler\generate-xspec-tests.xsl

If I replace the fragment:

<xsl:when test="$context">
   <!-- Set up the $context variable -->
   <xsl:apply-templates select="$context" mode="x:setup-context"/>
   <!-- Switch to the context and call the template -->
   <for-each select="$context">
     <xsl:copy-of select="$template-call" />
   </for-each>
</xsl:when>

with

<xsl:when test="$context">
   <!-- Set up the $context variable -->
   <xsl:apply-templates select="$context" mode="x:setup-context"/>
   <!-- Switch to the context and call the template -->
   <for-each select="$impl:context">
     <xsl:copy-of select="$template-call" />
   </for-each>
</xsl:when>

I can compile and run the XSpec without a problem.

I have no idea if this breaks something else, but it looks as though the intention in this stylesheet is to support a template call with context within a scenario.

@AirQuick
Copy link

Anyway, the schema xspec.rnc doesn't allow x:call after x:context...

@yamahito
Copy link

That's true, @AirQuick - but you should be able to achieve the same goal with nested scenario until and if they decide to fix the schema.

cirulls added a commit to xspec/xspec that referenced this issue Feb 21, 2016
- change schema to allow context in named scenario
- add $impl to context (now $impl:context)

References in original XSpec project:
PR 76: expath#76
issue 66: expath#66
cirulls referenced this issue in xspec/xspec Feb 21, 2016
PR-76 issue #66 allow context in named templates
shapiy pushed a commit to xmlrocks/xspec that referenced this issue Feb 26, 2016
innovimax pushed a commit to innovimax/xspec that referenced this issue Jan 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants