1

Im trying to get the values of the element skos:prefLabel which has a sibling skos:closeMatch. However, I'm seeing that there are other skos:prefLabel being preceding-siblings of skos:closeMatch. I'm currently working on the following:

<?xml version="1.0" encoding="utf-8" ?>
 <root>
 <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     xmlns:skosxl="http://www.w3.org/2008/05/skos-xl#"
     ....(namespaces deleted for brevity)
     xmlns:xml="http://www.w3.org/XML/1998/namespace">

  <skos:Concept rdf:about="http://aims.fao.org/aos/agrovoc/c_26321">
   <skos:prefLabel xml:lang="fa">آبیس ماریزی‌ای</skos:prefLabel>
   <skos:prefLabel xml:lang="en">Abies mariesii</skos:prefLabel>
    ....
  </skos:Concept>

  <skos:Concept>
    ....
  </skos:Concept>

  <skos:narrower rdf:resource="http://aims.fao.org/aos/agrovoc/c_1322232213779"/>
  <skos:narrower rdf:resource="http://aims.fao.org/aos/agrovoc/c_19"/>
  <skos:prefLabel xml:lang="ar">شوح</skos:prefLabel>
  <skos:prefLabel xml:lang="fa">آبیس</skos:prefLabel>
  <skos:prefLabel xml:lang="ko">전나무속</skos:prefLabel>
  <skos:prefLabel xml:lang="ja">モミ属</skos:prefLabel>
  <skos:prefLabel xml:lang="tr">Abies</skos:prefLabel>
     ....
  <skos:prefLabel xml:lang="es">Abies</skos:prefLabel>
  <skos:prefLabel xml:lang="en">Abies</skos:prefLabel>
     ....
  <skos:prefLabel xml:lang="hi">पलूदर</skos:prefLabel>
  <skos:prefLabel xml:lang="zh">冷杉属</skos:prefLabel>
  <skos:closeMatch>
   <rdf:Description rdf:about="http://d-nb.info/gnd/4184405-1">
    <skos:closeMatch rdf:resource="http://aims.fao.org/aos/agrovoc/c_10"/>
   </rdf:Description>
  </skos:closeMatch>
    ....
  </rdf:RDF>

The whole XSLT is the following:

<?xml version="1.0" encoding="UTF-8"?>
 <xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    ....(namespaces deleted for brevity)
 xmlns:ns1="http://art.uniroma2.it/ontologies/vocbench#"
 xmlns:void="http://rdfs.org/ns/void#">
<xsl:output method="text" omit-xml-declaration="yes" indent="no"/>

<xsl:template match="root">
 <xsl:for-each select="rdf:RDF">
 <xsl:text>START HERE</xsl:text>
 <xsl:text>&#13;&#10;</xsl:text>
 <xsl:text>=LDR  00000nam  2200000Ia 4500</xsl:text>
 <xsl:text>&#13;&#10;</xsl:text>
   ....
 <xsl:apply-templates select="skos:Concept" />
 <xsl:text>&#13;&#10;</xsl:text>
    ....
</xsl:for-each>
</xsl:template>

 <xsl:template match="skos:Concept/skos:prefLabel">
  <xsl:for-each select="//skos:closeMatch/preceding-sibling::skos:prefLabel" />
  <xsl:text>=306  \\$aclosematch$b</xsl:text>
  <xsl:value-of select="." />   
  <xsl:text>&#13;&#10;</xsl:text>
 </xsl:template> 
.....
</xsl:stylesheet>

So I should be getting the following:.

=306  //$aشوح
=306  //$aآبیس
=306  //$a전나무속
 ....
=306  //$aAbies

With the xslt above, I am instead getting all skos:prefLabel, that's why I mentioned in the opening line of my question that there are many skos:prefLabel aside from the one nearest skos:closeMatch. I also tried putting in value of select=preceding-sibling::skos:prefLabel and preceding-sibling::skos:prefLabel1 and various combination, either I'm getting the same set of so many skos:prefLabels or blanks. I hope you can help me with my question. TIA and cheers!

Note: the whole file is available here

schnydszch
  • 435
  • 5
  • 19
  • Your question is not clear. First, **all** the `skos:prefLabel` nodes are siblings of `skos:CloseMatch`. And the output you show us has data that is not in the input. – michael.hor257k Aug 07 '15 at 09:30
  • So the template should have [1] somewhere? شوح , آبیس and 전나무속 are actually in the input in my sample. The file is actually here: http://128.199.159.143/merged-file.xml. Thanks! – schnydszch Aug 07 '15 at 11:36
  • I don't know, because I don't understand what is your goal here. I suggest you minimize your example to only what's necessary to demonstrate the problem. Hint: most of us do not read Arabic, Farsi or Korean, thus find it difficult to correlate the input to the output (which do not match anyway - there's no "car", "cfa" or "cko" in the input). Please review: http://stackoverflow.com/help/how-to-ask and http://stackoverflow.com/help/mcve – michael.hor257k Aug 07 '15 at 11:46
  • Hi! I edited the question. I have actually indicated that I have not put the template yet to get the xml:lang attribute, but since it added confusion, I edited it. It's actually $c before the ar which means arabic, and already added the template in the edit. – schnydszch Aug 07 '15 at 11:56
  • 1
    And I have voted to close your question because "*Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself.*" – michael.hor257k Aug 07 '15 at 11:59
  • I edited my question and also fixed the xslt, I made a mistake in copy-paste of the codes. I hope this merits an unvote for to close the question. – schnydszch Aug 07 '15 at 14:26
  • I am afraid your question is still as unclear as it was when I wrote my first comment. There is only one `skos:closeMatch` node in your input. It has 9 `skos:prefLabel` siblings (all ptreceding), which can be selected by `//skos:closeMatch/preceding-sibling::skos:prefLabel`. You claim that your stylesheet gets all `skos:prefLabel` nodes in the document. That's not true. It gets none of them, because your `xsl:for-each` instruction is self-closed. – michael.hor257k Aug 07 '15 at 14:59

1 Answers1

0

changing select="//skos:closeMatch/preceding-sibling::skos:prefLabel" to select="//skos:closeMatch/preceding-sibling::skos:prefLabel[1]" should do what you want I hope..