Following this post Compare variable in preceding-sibling with current node, I tried to compare current node in order to remove duplicate occurrences.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE stylesheet [
<!ENTITY menu SYSTEM "verb.xml">
]>
<xsl:variable name="gram" as="xs:string*" select="*//gramGrp/string-join((iType/@value, mood/@value, tns/@value, subc/@value), '. ')"/>
<xsl:variable name="actor-affixes" as="xs:string*" select="*//gramGrp/string-join((per/@value, gen/@value, number/@value), '')"/>
<xsl:for-each select="w[@n | @lemma]">
<ul>
<li><xsl:variable name="inflected">
<xsl:for-each select="*/m[@type='pref']">
<xsl:value-of select="current()"/>
<xsl:choose>
<xsl:when test="."><xsl:text>-</xsl:text></xsl:when>
<xsl:otherwise/>
</xsl:choose>
</xsl:for-each>
<xsl:for-each select="*//m[@type='baseForm']">
<xsl:variable name="str1">
<xsl:value-of select="current()[not != c[@type['infix']]] |node()"/>
</xsl:variable>
<xsl:value-of select="translate(normalize-space($str1), ' ', '-')"/>
</xsl:for-each>
<xsl:for-each select="*//m[@type='suff']">
<xsl:variable name="str2">
<xsl:if test="position() = last()"><xsl:text>-</xsl:text><xsl:value-of select="."/></xsl:if>
</xsl:variable>
<xsl:value-of select="concat($str2, '')"/>
</xsl:for-each>
</xsl:variable>
<xsl:value-of select="$inflected"/>
<xsl:text>: </xsl:text>
<xsl:variable name="gram-affixes">
<xsl:if test="$gram = preceding-sibling::node()/$gram">
<xsl:value-of select="$gram"/>
</xsl:if>
<xsl:text>.</xsl:text>
<xsl:value-of select="$actor-affixes" separator=", "/><xsl:text>.</xsl:text>
</xsl:variable>
<xsl:value-of select="$gram-affixes"/>
</li>
</ul>
</xsl:for-each>
Content from TEI-XML
<w n="1" lemma="tmtḫṣ" xml:id="tmtḫṣ" ana="#mḫṣ">
<m type="base">
<m type="pref" ana="#pref-t">t</m>
<m type="baseForm">m<c type="infix" ana="#infix-t">t</c>ḫṣ</m>
</m>
</w>
<w n="2" lemma="tmḫṣ" xml:id="tmḫṣ" ana="#mḫṣ">
<m type="base">
<m type="pref" ana="#pref-t">t</m>
<m type="baseForm">mḫṣ</m>
</m>
</w>
<gramGrp type="baseForm" ana="#mḫṣ">
<gramGrp n="1" ana="#tmtḫṣ">
<iType ana="#sstem.Gt" value="Gt" type="semantic-variations"/>
<mood ana="#mood.ind" value="ind"/>
<tns ana="#sasp.imperf" value="imperf"/>
<subc ana="#strans" value="trans"/>
<gramGrp n="1.1" ana="#actor-affixes">
<per ana="#s2" value="2"/>
<gen ana="#smasc" value="m"/>
<number ana="#ssing" value="sg"/>
</gramGrp>
<gramGrp n="1.2" ana="#actor-affixes">
<per ana="#s3" value="3"/>
<gen ana="#sfem" value="f"/>
<number ana="#ssing" value="sg"/>
</gramGrp>
</gramGrp>
<gramGrp n="2" ana="#tmḫṣ">
<iType ana="#sstem.D" value="D" type="semantic-variations"/>
<mood ana="#mood.ind" value="ind"/>
<tns ana="#sasp.perf" value="perf"/>
<subc ana="#strans" value="trans"/>
<gramGrp n="1.1" ana="#actor-affixes">
<per ana="#s2" value="2"/>
<gen ana="#smasc" value="m"/>
<number ana="#ssing" value="sg"/>
</gramGrp>
<gramGrp n="1.2" ana="#actor-affixes">
<per ana="#s3" value="3"/>
<gen ana="#sfem" value="f"/>
<number ana="#ssing" value="sg"/>
</gramGrp>
</gramGrp>
</gramGrp>
I have also tried: <xsl:for-each select="distinct-values($gram)"><xsl:value-of select="normalize-space(.)"/></xsl:for-each>
(follwing Compare variable in preceding-sibling with current node) and <xsl:for-each select="$gram[not(. = preceding-sibling::node()/$gram)]"><xsl:value-of select="$gram"/></xsl:for-each>
. But it doesn't work...
The current output is:
<ul><li>t-m-t-ḫṣ: Gt. ind. imperf. transD. ind. perf. trans., 2msg, 3fsg, , 2msg, 3fsg.</li></ul>
<ul><li>t-mḫṣ: Gt. ind. imperf. transD. ind. perf. trans., 2msg, 3fsg, , 2msg, 3fsg.</li></ul>
But as you can see, occurrences following ':' are the same. It should be:
<ul><li>t-m-t-ḫṣ: Gt. ind. imperf. trans., 2msg, 3fsg.</li></ul>
<ul><li>t-mḫṣ: D. ind. perf. trans., 2msg, 3fsg.</li></ul>
UPDATE:
According to advice, I have updated a new version in order to include all TEI
element
. It's working fine. But I have added in comment <!-- -->
additional problem. I think I still don't understand how key
is working. I don't know if I need to add a new post -- if yes, apologize please -- : can you explain how key
is working?
TEI:
<entryFree n="6" xml:id="mḫṣ">
<form type="verb">
<orth>mḫṣ</orth>
</form>
<form type="inflected">
<w n="1" lemma="tmtḫṣ" xml:id="tmtḫṣ" ana="#mḫṣ">
<m type="base">
<m type="pref" ana="#pref-t">t</m>
<m type="baseForm">m<c type="infix" ana="#infix-t">t</c>ḫṣ</m>
</m>
</w>
<w n="2" lemma="tmḫṣ" xml:id="tmḫṣ" ana="#mḫṣ">
<m type="base">
<m type="pref" ana="#pref-t">t</m>
<m type="baseForm">mḫṣ</m>
</m>
</w>
<gramGrp type="baseForm" ana="#mḫṣ">
<gramGrp n="1" ana="#tmtḫṣ">
<iType ana="#sstem.Gt" value="Gt" type="semantic-variations"/>
<mood ana="#mood.ind" value="ind"/>
<tns ana="#sasp.imperf" value="imperf"/>
<subc ana="#strans" value="trans"/>
<gramGrp n="1.1" ana="#actor-affixes">
<per ana="#s2" value="2"/>
<gen ana="#smasc" value="m"/>
<number ana="#ssing" value="sg"/>
</gramGrp>
<gramGrp n="1.2" ana="#actor-affixes">
<per ana="#s3" value="3"/>
<gen ana="#sfem" value="f"/>
<number ana="#ssing" value="sg"/>
</gramGrp>
</gramGrp>
<gramGrp n="2" ana="#tmḫṣ">
<iType ana="#sstem.D" value="D" type="semantic-variations"/>
<mood ana="#mood.ind" value="ind"/>
<tns ana="#sasp.perf" value="perf"/>
<subc ana="#strans" value="trans"/>
<gramGrp n="1.1" ana="#actor-affixes">
<per ana="#s2" value="2"/>
<gen ana="#smasc" value="m"/>
<number ana="#ssing" value="sg"/>
</gramGrp>
<gramGrp n="1.2" ana="#actor-affixes">
<per ana="#s3" value="3"/>
<gen ana="#sfem" value="f"/>
<number ana="#ssing" value="sg"/>
</gramGrp>
</gramGrp>
</gramGrp>
</form>
<sense n="1" ana="#mḫṣ" xml:id="mḥṣ01">to fight</sense>
<sense n="2" ana="#mḥṣ" xml:id="mḥṣ02">to destroy</sense>
<re n="1" ana="#tmtḫṣ #mḫṣ01" type="inflected" >
<sense>She fought <span>iterative function // with <ref
target="../computation/corpus_ilimilku.xml#ktu1-3_ii_l6b_tḫtṣb">tḫtṣb</ref></span>
<span type="interp"><ref target="../computation/corpus_ilimilku.xml#ktu1-3_ii_l5b_6a_int">Hermeneutics</ref></span>
<span ana="../computation/corpus_ilimilku.xml#contend"><reftarget="../computation/corpus_ilimilku.xml#mḫṣ01">Taxonomy, subcategory ofcompetition verb: contend</ref></span>
</sense>
</re>
<re n="2" ana="#tmḫṣ #mḫṣ02" type="inflected">
<sense>She destroyed <span type="interp"><ref target="../computation/corpus_ilimilku.xml#ktu1-3_ii_l7_int">Hermeneutics</ref></span>
<span ana="../computation/corpus_ilimilku.xml#humiliation"><ref target="../computation/corpus_ilimilku.xml#mḫṣ02">Taxonomy, subcategory of emotion's verb as a concept of: humiliation</ref></span>
</sense>
</re>
</entryFree>
XSL updated:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:math="http://www.w3.org/2005/xpath-functions/math"
xmlns:map="http://www.w3.org/2005/xpath-functions/map"
xmlns:array="http://www.w3.org/2005/xpath-functions/array"
exclude-result-prefixes="xs math map array" version="3.0">
<xsl:output method="html" encoding="utf-8" doctype system="about:legacy-compat"/>
<xsl:mode on-no-match="shallow-copy"/>
<xsl:key name="gramGrp" match="gramGrp[@n and @ana]" composite="yes" use="@n, substring(@ana, 2)"/>
<!-- <xsl:key name="re" match="re[@n and @ana[1]]" composite="yes" use="@n, substring(@ana, 2)" /> -->
<xsl:template match="entryFree">
<xsl:variable name="orth" select="*/orth/text()" />
<h3><xsl:value-of select="$orth"/></h3>
<xsl:text> Mean.: </xsl:text><xsl:value-of select="*//following-sibling::sense[@xml:id]" separator=", " /><xsl:text>.</xsl:text>
<ul><xsl:for-each select="*/w[@n | @lemma]">
<xsl:variable name="pref" as="xs:string*" select="string-join(m[@type = 'base']/m, '')"/>
<xsl:variable name="referenced-gramGrp" select="key('gramGrp', (@n, @lemma))"/>
<xsl:variable name="gram" as="xs:string*" select="$referenced-gramGrp/string-join((iType/@value, mood/@value, tns/@value, subc/@value), '. ')"/>
<xsl:variable name="actor-affixes" as="xs:string*" select="$referenced-gramGrp/gramGrp/string-join((per/@value, gen/@value, number/@value), '')"/>
<!-- <xsl:variable name="referenced-re" select="key('re', (ancestor-or-self::w/@xml:id))" />
<xsl:variable name="trans" as="xs:string*" select="$referenced-re/string-join(following::re/sense, '')"/> -->
<li>
<xsl:value-of select="$pref"/>
<xsl:text>: </xsl:text>
<xsl:value-of select="$gram, $actor-affixes" separator=", "/>
<xsl:text>. </xsl:text>Trans.
<!-- <xsl:value-of select="$trans" separator=". "/> -->
</li>
</xsl:for-each></ul>
</xsl:template>
<xsl:template match="gramGrp"/>
<!-- <xsl:template match="re"/> -->
</xsl:stylesheet>
Output:
<h3>mḫṣ</h3>
Mean.: to fight, to destroy.
<ul>
<li>tmtḫṣ: Gt. ind. imperf. trans, 2msg, 3fsg. Trans.
<!-- '$trans'-->
</li>
<li>tmḫṣ: D. ind. perf. trans, 2msg, 3fsg. Trans.
<!-- $trans' -->
</li>
</ul>
Unfortunately, there is no output for $trans
. What do I get wrong?
The updated version can be found here: http://xsltfiddle.liberty-development.net/3Nqn5Y4
In advance, thanks for your kind support to a xsl
newbie.