I need to know the character that precedes a certain element using XSLT 1.0.
Example XML:
<p>Das <hi>Konzert</hi> brachte die „<hi>Sinfonie</hi>“ von Gassmann-<hi>Kröger</hi>.</p>
I need to examine all elements in this document and would expect my XSLT to return " ", "„" and "." as preceding characters, and " ", "“" and "-" as following characters.
I tried this:
<xsl:template match="hi">
<xsl:text>[</xsl:text>
<xsl:value-of select="substring(preceding-sibling::text(),string-length(preceding-sibling::text()))"/>
<xsl:text>|</xsl:text>
<xsl:value-of select="substring(following-sibling::text(),1,1)"/>
<xsl:text>]</xsl:text>
</xsl:template>
This works fine for the following character, but not for the preceding character. It always returns " ", which always seems to be, in this case, the final character of "Das ". What can I do?