2017-12-15 26 views
0

저는 XSLT의 초보자입니다. 내 콘텐츠는 TEI 파일에서 가져옵니다.XSL : 서로 다른 두 노드에서 비슷한 값 표시

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

: (@ana 항상 첫 번째 값) category/equiv[@xml:id] 경우 w[@type='verb' and @ana[1]] = 'qry', 디스플레이 요소 'w'@xml:id"href".

처음에는 아무런 문제가 없습니다. 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ṣ TMHS tṣmt 'tkt šnst tġll은 tgrs tmġyn tštql šb't tṯ'r ṯ'r tmtḫṣn t'n tḫtṣb tḥdy t [D] GDD ktu1-3_ii_l4b-5a_tqrykl'at tqry tmtḫṣ

: tḫtṣ TMHS tṣmt 'tkt šnst tġll은 tgrs tmġyn tštql šb't tṯ'r ṯ'r tmtḫṣn t'n tḫtṣb tḥdy t [D]는

를 대신 GDD

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

어쩌면 문제가 <xsl:if>에서 오는 것이 좋지 않습니까?

친절한 도움에 감사드립니다.

+0

XSLT 코드가 불통 될 수 있도록 입력 XML과 원하는 출력을 공유하세요 문제를 해결하려면? 사용중인 XSLT 버전을 공유하십시오. –

+0

감사! 나는 그것을했다. 문제가 어디서 발생했는지 살펴 보는 것으로 충분합니다. – Vanessa

답변

1

나는 당신의 질문을 잘 따르지 않지만 ana 속성의 특정 값을 가진 w 노드를 얻으 려한다면 키의 이점을 누릴 수 있습니다. 당신이 equiv 요소에 위치하는 경우

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

그런 다음, 당신은 너무

같은 일치 w 노드를 얻을 것
<xsl:for-each select="key('w', concat('#', @xml:id))"> 
+0

정말 고마워요! 그것은 완벽하게 작동합니다. – Vanessa

+0

방금'match = "w"'대신'''match = "w [@ type = 'verb']"'를 추가했습니다. – Vanessa