私はXSLTの初心者です。私のコンテンツはTEIファイルから来ます。例えばXSL:2つの異なるノードで類似している場合の値を表示
<!-- 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">
:
<!-- 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ファイルのセクション category/equiv[@xml:id]
場合とw[@type='verb' and @ana[1]]
= 'qry'
(@anaの常に最初の値)、要素'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 tqrytmtḫṣtḫtṣTMHStṣmt'tktšnsttġllするTGRtmġyntštqlšb'ttṯ'rṯ'rtmtḫṣnt'ntḫtṣbtḥdyT [D] GDD ktu1-3_ii_l4b-5a_tqrykl'at tqrytmtḫṣ
:tḫtṣTMHStṣmt'tktšnsttġllするTGRtmġyntštqlšb'ttṯ'rṯ'rtmtḫṣnt'ntḫtṣbtḥdyT [D]代わりにGDD
qry:ktu1-3_ii_l4b-5a_tqry 'tqry'、ktu1-4_ii_l10_qryt 'qryt'。
多分、問題は<xsl:if>
であり、それは良い選択ではありませんか?
ご協力ありがとうございます。
XSLTコードを微調整することができるように、入力XMLと所望の出力を共有してください。問題を解決するには?使用しているXSLTのバージョンを共有してください。 –
ありがとう!やったよ。問題がどこから来ているかを見ても十分だと思います。 – Vanessa