Say you have an XML element you want to read in an app, however you have multiple environments where the path of dependent files may change
<root>
<element ID="MyConfigFile" url="c:\Program Files\MyProgram\resources\MyProgramconfig.xml" />
<element ID="Executable" url="c:\Program Files\MyProgram\Prog.exe" />
</root>
...so you would want to make a reference to the relative directory
@path="c:\Program Files\MyProgram\"
<root>
<element ID="MyConfigFile" url="@path\resources\MyProgramconfig.xml" />
<element ID="Executable" url="@path\Prog.exe" />
</root>
Can you use a variable declared in the XML itself to reference the relative directory path?
An XML variable can be defined as a string or file reference variable. Regular XML variables and XML file reference variables can be defined in all host languages with a few exceptions. REXX supports file reference variables for XML. Java™ supports XML and file reference variables for XML.
You cannot - 'variables' in XSLT are actually more like constants in other languages, they cannot change value. Save this answer. Show activity on this post.
You would need to add a DOCTYPE declaration to your file, declare an entity there and then reference that entity in the document body.
<!DOCTYPE root [
<!ENTITY path "c:\Program Files\MyProgram">
]>
<root>
<element ID="MyConfigFile" url="&path;\resources\MyProgramconfig.xml" />
<element ID="Executable" url="&path;\Prog.exe" />
</root>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With