Preamble
In the usecase I try to solve, I could have in each document different speakers (with different first names, last names, nicknames, honorific titles…). The information related to each speaker are not universal and should still related to an xml document. So, we could not store this information in the xslt stylesheet.
The goal
So, the goal is just to store variables in the xml and then reuse it each time we need it.
Minimal Wworking Example
This is the xml file I make:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xtension-element-prefixes="dyn">
<xsl:variable name="socrate"> <!-- Variable declaration of the speaker Socrate -->
<longname>Socrate</longname>
<shortname>Soc</shortname>
</xsl:variable>
<body>
<speaker><xsl:copy select="$socrate" /></speaker>
</body>
</xsl:stylesheet>
The XSLT stylesheet:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xtension-element-prefixes="dyn">
<xsl:output method="html" indent="yes"/>
<xsl:template match="speaker">
<span class="speaker">
<xsl:value-of select="speaker" />
</span>
</xsl:template>
</xsl:stylesheet>
The result (using xsltproc stylesheet.xslt example.xml > test.html
):
Socrate
Soc
<span class="speaker"></span> <!-- ← This is the relevant line -->
As you see, the call to the variable $socrate
is just completely ignored.
The question
Is it possible to declare variables and reusite with the above way or with any other way? then how?