I'm using Oxygen XML editor 23.1. I'm working on a large corpus of text and would like to use the transformation to automatically add certain attributes and values to certain elements. In this case, I have a @correspUnic
attribute, created to add ugaritic glyphs from unicode decimal. The values of @correspUnic
depend on the Latinized characters between the elements. Here's an example of tei
encoding:
<w>bn</w>
<g>.</g>
<name>qdš</name>
<w>
<seg>ʾa</seg>
<unclear>b̊</unclear>
</w>
Expected result:
<w correspUnic='𐎁𐎐'>bn</w>
<g correspUnic='𐎟'>.</g>
<name correspUnic='𐎖𐎄𐎌'>qdš</name>
<w>
<seg correspUnic='𐎀'>ʾa</seg>
<unclear correspUnic='𐎁'>b̊</unclear>
</w>
I have tried several variants of an xsl
transformation file, but I confess that after several hours, I close to give up. Here is the last code, which sadly doesn't work:
<!-- Define the str-split function -->
<xsl:template name="str-split">
<xsl:param name="input" />
<xsl:param name="delimiter" select="''" />
<xsl:choose>
<xsl:when test="contains($input, $delimiter)">
<xsl:variable name="first" select="substring-before($input, $delimiter)" />
<xsl:variable name="rest" select="substring-after($input, $delimiter)" />
<char>
<xsl:value-of select="$first" />
</char>
<xsl:call-template name="str-split">
<xsl:with-param name="input" select="$rest" />
<xsl:with-param name="delimiter" select="$delimiter" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<char>
<xsl:value-of select="$input" />
</char>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Define Unicode data directly in the variable -->
<xsl:variable name="unicodeData">
<data>
<row>
<latin>ʾa</latin>
<Unicode>66432</Unicode>
</row>
<row>
<latin>b</latin>
<Unicode>66433</Unicode>
</row>
<row>
<latin>g</latin>
<Unicode>66434</Unicode>
</row>
<row>
<latin>ḫ</latin>
<Unicode>66435</Unicode>
</row>
<row>
<latin>d</latin>
<Unicode>66436</Unicode>
</row>
<!-- etc -->
</data>
</xsl:variable>
<xsl:template match="/">
<!-- Display the value of the variable $unicodeData -->
<xsl:message select="$unicodeData" />
<xsl:apply-templates/>
</xsl:template>
<!-- XSLT template for adding @correspUnic to w, g, unclear, name, seg, and supplied -->
<xsl:template match="w | g | unclear | name | seg | supplied">
<!-- Copy current element -->
<xsl:copy>
<!-- Apply rules to add @correspUnic to children -->
<xsl:apply-templates select="node()" />
<!-- Check whether the current element must have @correspUnic -->
<xsl:if test="self::name or self::seg or self::supplied or self::w or self::g or self::unclear">
<!-- Recover Latinized characters from textual descendants -->
<xsl:variable name="latinized">
<xsl:for-each select="descendant::text()">
<xsl:value-of select="." />
</xsl:for-each>
</xsl:variable>
<!-- Check if Latinized characters are detected -->
<xsl:if test="normalize-space($latinized)">
<!-- Use the str-split function to split the string -->
<xsl:variable name="correspUnicode">
<xsl:call-template name="str-split">
<xsl:with-param name="input" select="$latinized" />
</xsl:call-template>
</xsl:variable>
<!-- Add @correspUnic attribute with Unicode values -->
<xsl:attribute name="correspUnic">
<xsl:for-each select="$correspUnicode/char">
<xsl:variable name="char" select="." />
<xsl:if test="normalize-space($char)">
<xsl:value-of select="concat('&#', $unicodeData//row[latin = $char]/Unicode, ';')" />
</xsl:if>
</xsl:for-each>
</xsl:attribute>
</xsl:if>
</xsl:if>
</xsl:copy>
</xsl:template>
As you can see, I added xsl:message
to see any errors that would have a direct impact on adding the attribute and its values, but nothing...
Thank you very much in advance for your advice and suggestions.