[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: xslt create a variable from external xml file

Subject: Re: xslt create a variable from external xml file
From: "LEGAULT, PHILLIP plegault@xxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 22 Aug 2023 15:10:15 -0000
Re:  xslt create a variable from external xml file
This one gives me an error,
Error at xsl:param on line 266 column 107 of process.xsl:
  XPST0003 XPath syntax error at char 39 on line 266 near {...environment =>
    Unexpected token ">" in path expression
Error at xsl:param on line 266 column 107 of process.xsl:
  XPST0081 SequenceType syntax error at char 0 in {xs:string}:
    Undeclared namespace prefix {xs}
Failed to compile stylesheet. 2 errors detected.

From: Bauman, Syd s.bauman@xxxxxxxxxxxxxxxx
Sent: Tuesday, August 22, 2023 10:24 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [EXTERNAL] Re:  xslt create a variable from external xml file

Do you have control over the ./inc/env.xml file? If so, my thought would be to
skip the <root> and have it say

<?xml version="1.0" encoding="UTF-8"?>

(Just easier for humans to read, I think.)
Given that env file the following XSLT should do the trick (untested):

  <xsl:param name="env" select="document('./inv/env.xml')/environment =>
normalize-space()" as="xs:string"/>
  <!-- ... -->
      <xsl:when test="$env eq 'test'">
      <xsl:when test="$env eq 'prod'"/>
        <xsl:message terminate="yes" select="'I cannot figure out if I am on
"test" or "prod", so I am giving up.'"/>

If you do not have control over the env.xml file, use
document('./inv/env.xml')/root/environment instead. Note that using
<xsl:param> rather than <xsl:variable> is not at all necessary, it just allows
you to set the environment on any particular run by passing in a parameter.
(BTW, I have used a param for this sort of thing in the past, but never an
external file like that. From a bash script something like
  saxon -s:input.xml -xsl:transform.xslt -o:/tmp/output.xml host=$(hostname
allows me to test which machine I am running on. Warning, though, the above is
from memory, and mine is fading. :-)

Also note I did not bother with the <xsl:text></xsl:text> in the 'prod' clause
of the <choose>. Seems to me there is no point in asking the XSLT processor to
go through the hassle of creating a text node only to find there is nothing in
it, so it ends up disappearing, anyway.

I have a need to determine what environment I'm working on without hardcoding
the differences in the large xslt file.

I have tried

<xsl:variable name="externalDoc" select="document('inc/env.xml')"/>

File content

<?xml version="1.0" encoding="UTF-8"?>




And in the main xslt file I use, I just want to add a T at the end.


  <xsl:when test="$externalDoc/environment = 'test'">



  <xsl:when test="$externalDoc/environment = 'prod'">




XSL-List info and archive<http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe<http://lists.mulberrytech.com/unsub/xsl-list/649132> (by
XSL-List info and archive<http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe<http://lists.mulberrytech.com/unsub/xsl-list/3514465> (by

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.