xmlxsltxslt-1.0rdfskos

xslt get element value based on attribute which is referenced in another node tree


I have the following xml file:

 <?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#"
   xmlns:skos="http://www.w3.org/2004/02/skos/core#"
   xmlns:dc="http://purl.org/dc/terms/"
   xmlns:ns0="http://art.uniroma2.it/ontologies/vocbench#"
   xmlns:void="http://rdfs.org/ns/void#">

  <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:broader rdf:resource="http://aims.fao.org/aos/agrovoc/c_10"/>
  </skos:Concept>

  <skos:Concept rdf:about="http://aims.fao.org/skosmos/agrovoc/en/page/c_1591">
   <skos:prefLabel xml:lang="ar">أشجار عيد الميلاد</skos:prefLabel>
        ....
   <skos:prefLabel xml:lang="en">christmas trees</skos:prefLabel>
     ....

  </skos:Concept>

     ....

  <skos:Concept>
   <ns0:isUsedAs rdf:resource="http://aims.fao.org/skosmos/agrovoc/en/page/c_7776"/>
   <ns0:isUsedAs rdf:resource="http://aims.fao.org/skosmos/agrovoc/en/page/c_1591"/>
  </skos:Concept>

 </rdf:RDF>    
 </root>

I want to get the value of <skos:prefLabel xml:lang="en"> which has a parent skos:Concept and this skos:Concept is referenced in another node tree ns0:isUsedAs. Thus, we get the value of 'christmas tree' for ns0:isUsedAs rdf:resource="http://aims.fao.org/skosmos/agrovoc/en/page/c_1591. And I want to output this as text, same as below:

 =305  \\$aisUsedAs$bchristmas tree

Please take note that skos:prefLabel is a child of skos:Concept. ns0:isUsedas is a also child of skos:Concept, but is in another node tree. I also already have the following preliminary xsl:templates:

 <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="rdf:Description/skos:narrowMatch" />
   <xsl:text>&#13;&#10;</xsl:text>
  <xsl:apply-templates select="rdf:Description/skos:exactMatch" />
   <xsl:text>&#13;&#10;</xsl:text>
  <xsl:apply-templates select="skos:Concept" />
   <xsl:text>&#13;&#10;</xsl:text>
  <xsl:apply-templates select="skos:Concept/skos:altLabel" />
   <xsl:text>&#13;&#10;</xsl:text>
  <xsl:apply-templates select="skos:Concept/skos:prefLabel" />
   <xsl:text>&#13;&#10;</xsl:text>  
  </xsl:for-each>
 </xsl:template>

I hope you can help me with my problem. Thanks in advance!

further update:

Here is an xslt based from Dan's answer, but I'm still getting blanks:

 <xsl:transform
  ......
 >
<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="rdf:Description/skos:narrowMatch" />
   <xsl:text>&#13;&#10;</xsl:text>
   <xsl:apply-templates select="rdf:Description/skos:exactMatch" />
   <xsl:text>&#13;&#10;</xsl:text>
   <xsl:apply-templates select="skos:Concept" />
   <xsl:text>&#13;&#10;</xsl:text>
   <xsl:apply-templates select="skos:Concept/skos:altLabel" />
   <xsl:text>&#13;&#10;</xsl:text>
   <xsl:apply-templates select="skos:Concept/skos:prefLabel" />
   <xsl:text>&#13;&#10;</xsl:text>  
  </xsl:for-each>
 </xsl:template>
 <xsl:output method="text" omit-xml-declaration="yes" encoding="UTF-8" indent="no" />
 <xsl:key name="concepts-by-about" match="//skos:Concept" use="@rdf:about" />

    <xsl:template match="//ns0:isUsedAs[key('concepts-by-about', @rdf:resource)]">        
=305 \\$aisUsedBy$b<xsl:value-of select="key('concepts-by-about', @rdf:resource)/skos:prefLabel[@xml:lang='en']" />        
    </xsl:template>

    <xsl:template match="text()" />
 </xsl:transform>

Solution

  • This should get you started:

    <?xml version="1.0"?>
    
    <xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    
      xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
      xmlns:skos="http://www.w3.org/2004/02/skos/core#"
      xmlns:ns0="http://art.uniroma2.it/ontologies/vocbench#"
    >
    
      <xsl:template match="/">
        <xsl:for-each select="//skos:Concept/ns0:isUsedAs/@rdf:resource">
          <xsl:variable name='resource' select="."/>
          <xsl:value-of select="//skos:Concept[@rdf:about=$resource]/skos:prefLabel[@xml:lang='en']"/>
        </xsl:for-each>
      </xsl:template>
    
    </xsl:stylesheet>