How to read a .properties file inside a .xsl file?

I have an XSL file which uses a a static website link as shown below:

<xsl:template match="my_match">

    <xsl:variable name="variable1">
        <xsl:value-of select="sel1/Label = 'Variable1'"/>
    <xsl:copy-of select="sites:testPath('', $fname, $lname,
     $email , $zip, $phone, $comments, $jps, boolean($myvar), string(cust/@custID), string(@paID))"/>

My question is that how to read a properties file(key value pair) in the xsl file. so in my properties file (e.g. I have a key called site i.e.

I want to use this site key in place of specifying url value in the xsl i.e. The reason for doing this is that this link changes depending on the various environments.

Is this possible? Please give your suggestions or a sample code if possible...Also if this is not there any work-around?


As a proof of concept:

Input .properties file:

# You are reading the ".properties" entry.
! The exclamation mark can also mark text as comments.
website =
language = English
key\ with\ spaces = This is the value that could be looked up with the key "key with spaces".


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl=""

  <xsl:variable name="properties" select="unparsed-text('.properties')" as="xs:string"/>

  <xsl:template match="/" name="main">
    <xsl:value-of select="f:getProperty('language')"/>

  <xsl:function name="f:getProperty" as="xs:string?">
    <xsl:param name="key" as="xs:string"/>
    <xsl:variable name="lines" as="xs:string*" select="
      for $x in 
        for $i in tokenize($properties, '\n')[matches(., '^[^!#]')] return
          tokenize($i, '=')
        return translate(normalize-space($x), '\', '')"/>
    <xsl:sequence select="$lines[index-of($lines, $key)+1]"/>


The f:getProperty('language') will return 'English'.

See this as a proof of concept, this needs to be improved in many ways since it does not handle many of the different ways a .properties file can be authored.

I belive Alejandro or Dimitrie probably could improve this many times.

For an XSLT 1.0 solution, you could use an external (parsed) general entity in an XML file that will load the properties file as part of the XML content.

For example, if you had a properties file like this, named


You could create a simple XML file, named properties.xml that "wraps" the content of the properties file and loads it using an external parsed general entity:

<!DOCTYPE properties [
  <!ENTITY props SYSTEM "">

Then, within your XSLT you can load that properties.xml using the document() function and obtain the value for a given key:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

    <xsl:variable name="props" select="document('properties.xml')" />
    <xsl:template match="/">
                <!--simple one-liner -->
                <xsl:value-of select="substring-before(
                                        '&#xA;')" />
                <!--using a template to retrieve the value 
                    of the "site" property -->
                <xsl:call-template name="getProperty">
                    <xsl:with-param name="propertiesFile" select="$props"/>
                    <xsl:with-param name="key" select="'site'"/>
                <!--Another example using the template to retrieve 
                    the value of the "foo" property, 
                    leveraging default param value for properties -->
                <xsl:call-template name="getProperty">
                    <!--default $propertiesFile defined in the template, 
                        so no need to specify -->
                    <xsl:with-param name="key" select="'foo'"/>


    <!--Retrieve a property from a properties file by specifying the key -->
    <xsl:template name="getProperty">
        <xsl:param name="propertiesFile" select="$props"/>
        <xsl:param name="key" />
        <xsl:value-of select="substring-before(
                                 '&#xA;')" />


When applied to any XML input the stylesheet above will produce the following output:

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

Note: this strategy will only work if the content of the properties file is "XML safe". If it were to contain characters, like & or < it would result in an XML parsing error when the properties.xml file is loaded.

Need Your Help

Unknown system variable 'sql_mode' error upon connecting to MySQL server 4.0.18 with mysql2

mysql ruby-on-rails ruby-on-rails-4

I'm trying to connect to an external database from my Rails 4.2.3 app with mysql2 0.3.18, but I keep getting the following error in my view:

Is it possible to have an autocomplete using jtextfield and a Jlist?

java swing autocomplete jtextfield jcombobox

I want to create an auto-complete program in java which should provide a list of suggestions instantly when the user types a character/String inside a JTextfield. The problem is that I am confused ...