xsl: check if both strings are equal, if true then display another string

xml xslt xslt-3.0 tei

67 观看

2回复

54 作者的声誉

I have a first TEI which content is used for XSLT that you can find here http://xsltfiddle.liberty-development.net/3Nqn5Y4/7

A second TEI in corpus_ilimilku.xml which I need to use in the same XSLT file:

<category n="1"  xml:id="contend" ana="#verb.competition">
     <catDesc xml:lang="en">subcategory of competition verb: contend 
         <lang> 
             <ref n="1" target="http://babelnet.org">BabelNet<idno type="URI">http://live.babelnet.org/synset?word=bn:00083498v</idno></ref>
             <ref n="2" target="https://framenet2.icsi.berkeley.edu/">FrameNet<idno type="URI">https://framenet2.icsi.berkeley.edu/fnReports/data/frameIndex.xml?frame=Attaching"></idno></ref>
         </lang>
      </catDesc> 
      <category ana="#transcription" xml:lang="uga">
          <gloss n="1" xml:id="ḫṣb01" target="../uga/verb.xsl#ḫṣb"/>
          <gloss n="2" xml:id="mḫṣ01" cert="high" target="../uga/verb.xsl#mḫṣ"/> 
      </category>
</category>

I don't have a problem to refer to the right file. I have checked, and it's working.

In fact, I have two problems:

  1. key of ref that is not working I think,
  2. so when I want to display href5 of $value-doc2 if "$value-doc = translate($re-ana2, '#', '') is true, I have the following message:

Description: A sequence of more than one item is not allowed as the first argument of tokenize() (", "http://live.babelnet.org/synse...", "https://framenet2.icsi.berkeley.edu...")

Currently, "$value-doc = translate($re-ana2, '#', '') works since I have tested with several values, and the result is true or false. See last word of each <li>print screen for <code>$check-id</code>

What I would like to display:

<h3>mḫṣ</h3><em>
mean.: </em>to figth, to destroy. Inflected forms attested:
<ul>
 <li>tmtḫṣ: gram. → Gt. ind. imperf. trans, 2msg, 3fsg. <em>trans. </em>she fought -- remark(s): iterative function // with “<a href="../computation/corpus_ilimilku.xml#ktu1-3_ii_l6b_t%E1%B8%ABt%E1%B9%A3b">tḫtṣb</a>.” Occur.: <a href="">ktu1.3:ii:l5b-6a</a> -- <em>analysis: </em>suggestion of 
  <a href="../computation/corpus_ilimilku.xml#ktu1-3_ii_l5b_6a_int">hermeneutics;</a> taxo., subcat. of competition v. “<a href="../computation/corpus_ilimilku.xml#m%E1%B8%AB%E1%B9%A301">contend</a>.” 
   <!-- DATA THAT I CANNOT DISPLAY : --> <a href="http://live.babelnet.org/synset?word=bn:00083498v">BabelNet</a>, <a href="https://framenet2.icsi.berkeley.edu/fnReports/data/frameIndex.xml?frame=Attaching">Framework</a>
  </li>
  <li>tmḫṣ: gram. → D. ind. perf. trans, 2msg, 3fsg. <em>trans. </em>she destroyed -- remark(s): 
  Occur.: <a href="">ktu1.3:ii:l7</a> -- <em>analysis: </em>suggestion of <a href="../computation/corpus_ilimilku.xml#ktu1-3_ii_l7_int">hermeneutics;</a> taxo., subcat. of emotion's v. as a concept of “<a href="../computation/corpus_ilimilku.xml#m%E1%B8%AB%E1%B9%A302">humiliation</a>.” 
   <!-- DATA THAT I CANNOT DISPLAY : --> <a href="http://live.babelnet.org/synset?word=bn:00083498v">BabelNet</a>, <a href="https://framenet2.icsi.berkeley.edu/fnReports/data/frameIndex.xml?frame=Attaching">Framework</a>
 </li>
</ul>

To sum up: if @xml:id of <gloss> of second TEI (corpus_ilimilku.xml) = @ana[2] of <re> of current TEI (in Fiddle content), then display idno @type URI of each ref that belongs to same parent node of gloss.

I hope my explanation is clear. Sorry for my lack of English...

In advance, thank you.

作者: Vanessa 的来源 发布者: 2017 年 12 月 27 日

回应 2


2

118712 作者的声誉

If the line

<!-- DATA THAT I CANNOT DISPLAY : --> <a href="http://live.babelnet.org/synset?word=bn:00083498v">BabelNet</a>, <a href="https://framenet2.icsi.berkeley.edu/fnReports/data/frameIndex.xml?frame=Attaching">Framework</a>

is meant to explain that you want to transform the

document('../computation/corpus_ilimilku.xml')//lang/ref/idno

elements into links then where you want to create those links use

<xsl:apply-templates select="document('../computation/corpus_ilimilku.xml')//lang/ref/idno"/>

and then write a template

<xsl:template match="idno">
  <a href="{.}">
    <xsl:value-of select="preceding-sibling::node()[1]"/>
  </a>
</xsl:template>

that produces those links (I am not quite sure about the link content, for the first BabelNet seems as described, for the second the is FrameNet versus Framework).

As for using keys with several documents, keys work on a per document basis and the key function has an optional third argument you can specify to search e.g $doc2 with values from the context document with e.g. key('key-name', (key-value-or-values), $doc2).

I think your verbal description

if @xml:id of of second TEI (corpus_ilimilku.xml) = @ana[2] of of current TEI (in Fiddle content), then display idno @type URI of each ref that belongs to same parent node of gloss

translates into a key declaration

<xsl:key name="gloss-ref" match="category[category/gloss]" use="category/gloss/@xml:id"/>

then let's assume we have a global variable <xsl:variable name="doc2" select="doc('../computation/corpus_ilimilku.xml')"/> I think you want to use the key function with e.g.

<xsl:apply-templates select="key('gloss-ref', $re-ana2, $doc2)//lang/ref/idno"/>

to process the relevant idno elements.

作者: Martin Honnen 发布者: 2017 年 12 月 27 日

0

54 作者的声誉

决定

I found the solution with the kind support of @Martin. First, I changed second TEI:

  <category n="1" xml:id="humiliation" ana="#verb.emotion">
     <catDesc >subcategory of emotion's verb as a concept of: humiliation
       <term ana="#mḫṣ02 #ṣmt01" type="baseForm">
          <ptr n="1" target="http://babelnet.org/synset?word=bn:00086117v" source="BabelNet" />
          <ptr n="2" target="" source="WordNet" next="{01804206}" />
          <ptr n="3" target="http://verbs.colorado.edu/propbank/framesets-english-aliases/humiliate.html" source="VerbNet" />
          <ptr n="4" target="http://verbs.colorado.edu/html_groupings/wound-n.html" source="VerbNet" />
          <ptr n="5" target="https://framenet2.icsi.berkeley.edu/fnReports/data/frameIndex.xml?frame=Stimulate_emotion" source="FrameNet" />
        </term>
      </catDesc>
      <category ana="#verb.emotion #humiliation" xml:lang="uga">
          <gloss n="1" xml:id="mḫṣ02" cert="high"/> 
      </category>  
    </category> 

Then for XSL, following addition:

<xsl:param name="f2" select="'../computation/corpus_ilimilku.xml'"/>

<!-- key to look for @xml:id of <gloss> within TEI -->
<xsl:key name="gloss-ref" match="category[category/gloss]" use="category/gloss/@xml:id"/>
<!-- variable for "f2" -->
<xsl:variable name="doc2" select="document($f2)"/>

<!-- within template match="entryFree" and <ul><li> -->
<xsl:apply-templates select="key('gloss-ref', translate($re-ana2, '#', ''), $doc2)//term/ptr[@target]"/>

<!-- template to display <xsl:apply-templates> -->
<xsl:template match="ptr">
    <xsl:variable name="href-ptr-target" select="@target"/>
    <a href="{$href-ptr-target}">
     <xsl:value-of select="@source"/>
     <xsl:if test="@next">
      <xsl:value-of select="@next"/>
     </xsl:if>
    <xsl:choose> <xsl:when test="position() != last()">
        <xsl:text>, </xsl:text> </xsl:when>
        <xsl:otherwise><xsl:text>. </xsl:text></xsl:otherwise>
    </xsl:choose></a>
</xsl:template> 

Result, according to Fiddle http://xsltfiddle.liberty-development.net/3Nqn5Y4/9, new XSL (between <!-- --> in Fiddle), and second TEI content:

<ul>
  <li>tmḫṣ: gram. → D. ind. perf. trans, 2msg, 3fsg. <em>trans. </em>she destroyed -- remark(s): Occur.: <a href="">ktu1.3:ii:l7</a> -- <em>analysis: </em>suggestion of <a href="../computation/corpus_ilimilku.xml#ktu1-3_ii_l7_int">hermeneutics;</a> taxo., subcat. of emotion's v. as a concept of “<a href="../computation/corpus_ilimilku.xml#m%E1%B8%AB%E1%B9%A302">humiliation</a>.” Related to: <a href="http://babelnet.org/synset?word=bn:00086117v">BabelNet, </a><a href="">WordNet{01804206}, </a><a href="http://verbs.colorado.edu/propbank/framesets-english-aliases/humiliate.html">VerbNet, </a><a href="http://verbs.colorado.edu/html_groupings/wound-n.html">VerbNet, </a><a href="https://framenet2.icsi.berkeley.edu/fnReports/data/frameIndex.xml?frame=Stimulate_emotion">FrameNet.</a></li>
</ul>
作者: Vanessa 发布者: 2017 年 12 月 31 日
32x32