【问题标题】:xsl: check if both strings are equal, if true then display another stringxsl:检查两个字符串是否相等,如果为真则显示另一个字符串
【发布时间】:2018-06-08 08:14:00
【问题描述】:

我有第一个TEI,其中的内容用于XSLT,你可以在这里找到http://xsltfiddle.liberty-development.net/3Nqn5Y4/7

corpus_ilimilku.xml 中的第二个TEI 我需要在同一个XSLT 文件中使用:

<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>

引用正确的文件没有问题。我已经检查过了,它正在工作。

其实我有两个问题:

  1. 我认为keyref 不起作用,
  2. 所以当我想显示$value-doc2href5 时,如果"$value-doc = translate($re-ana2, '#', '') 为真,我有以下消息:

说明:多于一项的序列不允许作为 tokenize() 的第一个参数 (", "http://live.babelnet.org/synse...", "https://framenet2.icsi.berkeley.edu...")

目前,"$value-doc = translate($re-ana2, '#', '') 有效,因为我已经测试了几个值,结果是truefalse。查看每个&lt;li&gt;的最后一句话

我想显示的内容:

<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>

总结一下:如果@xml:id of 第二个TEI (corpus_ilimilku.xml) = @ana[2] of &lt;re&gt; of current TEI (in Fiddle content),则显示idno @type URI of每个ref 属于gloss 的同一父节点。

我希望我的解释清楚。对不起,我的英语不好...

提前,谢谢。

【问题讨论】:

  • 正确答案如下。

标签: xml xslt xslt-3.0 tei


【解决方案1】:

在@Martin 的大力支持下,我找到了解决方案。一、我换了第二个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> 

那么对于XSL,加法如下:

<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> 

结果,根据小提琴http://xsltfiddle.liberty-development.net/3Nqn5Y4/9,新XSL(在小提琴&lt;!-- --&gt;之间),第二个TEI内容:

<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>

【讨论】:

    【解决方案2】:

    如果行

    <!-- 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>
    

    是为了说明你要改造的

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

    将元素放入链接,然后在您要创建这些链接的位置使用

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

    然后写一个模板

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

    生成这些链接(我不太确定链接内容,因为第一个 BabelNet 似乎与描述的一样,第二个是 FrameNetFramework)。

    至于对多个文档使用键,键在每个文档的基础上工作,key 函数有一个可选的第三个参数,您可以指定使用上下文文档中的值来搜索例如$doc2,例如key('key-name', (key-value-or-values), $doc2).

    我认为你的口头描述

    如果@xml:id of 第二个 TEI (corpus_ilimilku.xml) = @ana[2] of 当前 TEI(在 Fiddle 内容中),然后显示 idno @type URI 属于gloss的同一个父节点的每个ref

    转化为密钥声明

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

    那么让我们假设我们有一个全局变量&lt;xsl:variable name="doc2" select="doc('../computation/corpus_ilimilku.xml')"/&gt; 我想你想使用 key 函数,例如

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

    处理相关的idno 元素。

    【讨论】:

    • 谢谢@Martin!我想我现在了解apply-templates。关于key,我现在做了:&lt;xsl:choose&gt; &lt;xsl:when test="$check-id = true()"&gt; &lt;xsl:if test="key('ref', @n and @type, document('../computation/corpus_ilimilku.xml'))"/&gt; &lt;xsl:apply-templates select="$idno-ref"/&gt;&lt;/xsl:when&gt;&lt;xsl:otherwise/&gt; &lt;/xsl:choose&gt;(其中$idno-ref 代表document('../computation/corpus_ilimilku.xml')//lang/ref/idno),但我拥有每个字符串$check-id = true() 的所有idno 文档。我怎么了?
    • link 的最后一个答案之后,我也尝试过xsl:for-each 而不是xsl:if,但还是不行。
    • 为什么key('ref', @n and @type ...) 使用布尔表达式@n and @type 作为键值?
    • 对。所以我换了&lt;xsl:if test="$check-id"&gt;。我只想在$check-id 时显示内容。但我仍然拥有所有idno 和多次string
    • 我找到了解决方案。刚刚更新了新答案。再次感谢@Martin。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-10-30
    • 1970-01-01
    • 2019-05-11
    • 2012-10-15
    • 2013-05-12
    • 1970-01-01
    相关资源
    最近更新 更多