XSLT with externally set variables does not compile

Having trouble installing <oXygen/>? Got a bug to report? Post it all here.
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"
  <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'">

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,
Posts: 2471

Re: XSLT with externally set variables does not compile

Tue Sep 27, 2016 8:45 pm


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.

Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
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.

Return to “Common Problems”

Who is online

Users browsing this forum: No registered users and 2 guests