XSLT with externally set variables does not compile

Having trouble installing <oXygen/>? Got a bug to report? Post it all here.
cal
Posts: 3

XSLT with externally set variables does not compile

Tue Sep 27, 2016 6:22 pm

I am trying to create a debug scenario to profile my XSLT transforms. The main XSLT has variables which I can pass to it in my rails application via nokogiri XSLT transform API. However, when I create the scenario I am unable to have to variable substitution take place correctly. Main XSLT (I must use 1.0 due to a ruby gem that only supports 1.0):

Code: Select all

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:csw="http://www.opengis.net/cat/csw/2.0.2">
  <xsl:output method="xml" indent="yes"/>
  <xsl:include href="csw_common.xslt" />
  <xsl:template match="/">
    <xsl:element name="{$result_root_element}">
      <xsl:if test="$result_root_element = 'MyStringValueSetOutside XSLT'">
etc.


When I execute the scenario, I get an error 'W[Saxon6.5.5] Variable result_root_element has not been declared'. I tried both parameter definitions (which I didn't really expect to work since the XSLT does not have parameters) and editor variables. With the editor variables, it seems like the variable is created as ${root_result_element} and perhaps what is why the compilation fails. Any suggestions?
Thank you,
Cal
adrian
Posts: 2336

Re: XSLT with externally set variables does not compile

Tue Sep 27, 2016 8:45 pm

Hi,

Why aren't you declaring the variable in the stylesheet?
Before executing the scenario/stylesheet, validate it and fix the reported errors (e.g. Missing declarations).
Some API may let you set up the variables and then run the stylesheet in that environment, but that doesn't eliminate the need for a valid XSLT(proper declarations), especially if you'll ever want to use it without that API.

Did you try to assign a value to the variable under Parameters from the transformation scenario (but this would still assume you have declared the variable)?

Oxygen editor variables cannot be used in stylesheets. That is not their purpose.

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
cal
Posts: 3

Re: XSLT with externally set variables does not compile

Tue Sep 27, 2016 11:21 pm

Hi Adrian,
Thank you very much for your prompt response. I am using a ruby gem (Nokogiri) which relies on an old version of libxml which is much more permissive with the XSLT syntax.
I followed your suggestion and declared variables that are set via XSLT parameters and everything worked as expected. I was able to profile the XSLT.
I very much appreciate your help.
Regards,
Cal

Return to “Common Problems”

Who is online

Users browsing this forum: No registered users and 0 guests