XSL:如果在两个不同的节点中相似,则显示值

时间:2017-12-15 02:56:33

标签: xml xslt tei

我是XSLT的初学者。我的内容来自TEI文件。

<!-- language: XSLT -->
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE stylesheet [
 <!ENTITY menu SYSTEM "corpus.xml"> 


]> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.w3.org/1999/xhtml"
xpath-default-namespace="http://www.tei-c.org/ns/1.0" exclude-result-prefixes="xs" version="2.0">
<xsl:output method="html" encoding="utf-8" doctype-system="about:legacy-compat"/>
<!-- delete extra blank lines -->
<xsl:strip-space elements="*"/>

<xsl:template match="/">
 <html>
  <head/>
  <body>
   <ul>
    <xsl:apply-templates select="descendant::taxonomy[2]/category[4]"/>
   </ul>
  </body>
 </html>
</xsl:template>

<xsl:template match="taxonomy[2]/category[4]">
<!-- several other 'xsl:for-each' within <ul> before the following <ul> --> 
<!-- each verb related to a sub-category ('category/category') in TEI -->
<ul>
 <xsl:for-each select="following-sibling::category/equiv[@n]">
  <li>
  <!-- @uri = @xml:id in TEI -->
    <xsl:variable name="href"><xsl:value-of select="@uri"/></xsl:variable>
    <a href="{$href}"> 
     <xsl:value-of select="./@*[namespace-uri()='http://www.w3.org/XML/1998/namespace' and local-name()='id']"/></a>:
   <!-- ### Problem starts here: find same value in element 'w' and element 'equiv' -->                            
   <xsl:for-each select="//w[@type='verb']">
   <!-- @xml:id in TEI -->
     <xsl:variable name="href"><xsl:value-of select="@xml:id"/> </xsl:variable>
     <a href="{$href}"> 
        <xsl:value-of select="./@*[namespace-uri()='http://www.w3.org/XML/1998/namespace' and local-name()='id']" /></a>
      <!-- look to first value of @ana of element 'w' = value of @xml:id of element 'equiv'  -->
         <xsl:if test="//w[@type='verb' and @ana[1]] = preceding::category/equiv/@*[namespace-uri()='http://www.w3.org/XML/1998/namespace' and local-name()='id']">
          <xsl:value-of select="//w[@type='verb'and @ana[1]]"/></xsl:if>
   </xsl:for-each>
  </li>
 </xsl:for-each>
</ul>
</xsl:stylesheet>

我的TEI-XML文件的一部分:

<!-- language TEI-XML -->
<!-- XPATH: /teiCorpus/teiHeader[1]/encodingDesc[1]/classDecl[1]/taxonomy[2]/category[4]/category[9] -->
<category n="9" xml:id="verb.motion" ana="#verb.category #action">
 <catDesc>taxonomy: motion verbs</catDesc>
 <category n="1" xml:id="meeting" ana="#verb.motion"> 
  <catDesc>subcategory of motion's verb as a concept: meeting  
  </catDesc>
  <category ana="#transcription" xml:lang="uga">
   <equiv n="1" xml:id="qry"/>
  </category>
 </category>

<!-- section taht gave me trouble to find data in XSLT -->
<!-- XPATH /teiCorpus/text[1]/body[1]/div1[2]/div2[2]/div3[2]/div4[2]/lg[1]/l[1]/w[2] -->
<w type="verb" ana="#qry #yQTL" xml:id="ktu1-3_ii_l4b-5a_tqry">

例如: 如果category/equiv[@xml:id]w[@type='verb' and @ana[1]] = 'qry'(始终是@ana的第一个值),请显示"href"元素@xml:id的{​​{1}}。

我对第一个'w'没有问题。我有我想要的东西。 不幸的是select="following-sibling::category/equiv[@n]",我试过的东西不起作用:而不是@xml:id的类似“href”,我有所有“href”和@ana的第一个值。

目前的结果:

  

QRY:ktu1-3_ii_l3b-4a_kl'atkl'at tqrytmtḫṣtḫtṣTMHS TSMT'tktšnsttġll的TGRtmġyntštqlšb'ttṯ'rṯ'rtmtḫṣnt'ntḫtṣbtḥdy吨[d] GDD ktu1-3_ii_l4b-5a_tqrykl'at tqrytmtḫṣtḫtṣTMHS TSMT'tktšnsttġll的TGRtmġyntštqlšb't t t t t t t t t t t [d]ġdd

而不是:

  

qry:ktu1-3_ii_l4b-5a_tqry'tqry',ktu1-4_ii_l10_qryt'qryt'。

也许这个问题来自select="//w[@type='verb']"这不是一个好选择?

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

我不太关注您的问题,但是如果您尝试在w属性中获取具有特定值的ana节点,则可能会从密钥中受益。

<xsl:key name="w" match="w" use="tokenize(@ana, ' ')" />

然后,如果您位于equiv元素上,您将得到匹配的w节点,如此

<xsl:for-each select="key('w', concat('#', @xml:id))">