0

我是 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元素'w'

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

当前结果:

qry: ktu1-3_ii_l3b-4a_klʾatklʾat tqry tmtḫṣ tḫtṣ tmḫṣ tṣmt ʿtkt šnst tġll tgrš tmġyn tštql šbʿt tṯʿr ṯʿr tmtḫṣn tʿn tḫtṣb tḥdy t[d]ġdd ktu1-3_ii_l4b-5a_tqryklʾat tqry tmtḫṣ tḫtṣ tmḫṣ tṣmt ʿtkt šnst tġll tgrš tmġyn tštql šbʿt tṯʿr ṯʿr tmtḫṣn tʿn tḫtṣb tḥdy t[d]ġdd

代替:

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

也许问题出在<xsl:if>哪个不是好选择?

谢谢你的帮助。

4

1 回答 1

1

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

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

然后,如果你定位在equiv元素上,你会得到这样的匹配w节点

<xsl:for-each select="key('w', concat('#', @xml:id))">
于 2017-12-15T16:34:51.300 回答