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:variable>
<xsl:copy-of select="sites:testPath('http://testsite.com/services/testService/v1.0', $fname, $lname,
$email , $zip, $phone, $comments, $jps, boolean($myvar), string(cust/@custID), string(@paID))"/>
</xsl:template>
My question is that how to read a properties file(key value pair) in the xsl file. so in my properties file (e.g. site.properties) I have a key called site
i.e. site=testsite.com/services/testService/v1.0
I want to use this site key in place of specifying url value in the xsl i.e. http://testsite.com/services/testService/v1.0. 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 possible...is there any work-around?
As a proof of concept:
Input .properties file:
Stylesheet:
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
site.properties
: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:Then, within your XSLT you can load that
properties.xml
using thedocument()
function and obtain the value for a given key:When applied to any XML input the stylesheet above will produce the following output:
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 theproperties.xml
file is loaded.