0

I have the following xml:

<?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 "christmas tree" which is skos:prefLabel xml:lang="en" based on ns0:issuedAs which I'm not sure is a sibling, and also get the rdf:resource for such (e.g. http://aims.fao.org/skosmos/agrovoc/en/page/c_1591).

Or to rephrase what I wanted to do:

Select skos:Concept/skos:prefLabel where attribute language is en based on the value of skos:Concept rdf:about (in this case http://aims.fao.org/skosmos/agrovoc/en/page/c_1591) and this particular concept (still the "christmas tree" concept) has a node element ns0:isUsedAs (in this case again http://aims.fao.org/skosmos/agrovoc/en/page/c_1591).

1) We start with skos:prefLabel, the one with the xml:lang attribute of "en", in this case it's christmas trees 2) This concept has a parent node Skos:Concept with attribute rdf:about equals to "http://aims.fao.org/skosmos/agrovoc/en/page/c_1591" 3) This attribute is attributed in another tree, in ns0:isUsedAs rdf:resource. 4) So this christmas tree is identified through all of this.

So I can get the following text:

=304  \\$aisUsedas$bchristmas tree$chttp://aims.fao.org/skosmos/agrovoc/en/page/c_1591

Thanks in advance!

schnydszch
  • 435
  • 5
  • 19
  • 1
    It's hard to understand let alone translate it to XPath/XSL. Can you reword the requirement to be something like '*select something where some criteria*', or maybe using some kind of pseudo-code? – har07 Jul 24 '15 at 10:32
  • reworded my question. Added a more thorough phrase on what I wanted with my xml. – schnydszch Jul 24 '15 at 11:41
  • 1
    I am afraid it's still not clear. Where is the first "en" coming from? I suggest you reword this again and put it in three or four easy steps, instead of a single large sentence (just like if you had to explain to someone who is not very smart how to do this manually). – michael.hor257k Jul 24 '15 at 11:49
  • P.S. Please add the namespace declarations to your input example, so that it can be used for testing without requiring us to do modifications. -- And also state if using XSLT 1.0 or 2.0. – michael.hor257k Jul 24 '15 at 11:54
  • You've lost me at step 1). There are **two** `skos:prefLabel` nodes with the xml:lang attribute of "en". – michael.hor257k Jul 24 '15 at 14:27
  • Yes, the first is a different node tree for skos:Concept, I just put the first Skos:concept to show that there are many Skos:concept with the particular xml I am working with.The first skos:Concept shows that is a broader concept while the second one does not show anything but I have to get the linking from a separate node tree in the document to show "usedAs". The RDF/XML of this is available: http://aims.fao.org/skosmos/rest/v1/agrovoc/data?uri=http%3A%2F%2Faims.fao.org%2Faos%2Fagrovoc%2Fc_10&format=application/rdf%2Bxml. – schnydszch Jul 24 '15 at 14:56
  • A tabular presentation of this is available here: http://aims.fao.org/skosmos/agrovoc/en/page/c_10 – schnydszch Jul 24 '15 at 14:56
  • I am afraid this is not getting any clearer, and there is only so much time I can afford to spend here. Good luck. – michael.hor257k Jul 24 '15 at 17:54
  • Hi! I think my question is related to this stackoverflow question:http://stackoverflow.com/questions/4994919/how-to-use-attribute-values-from-another-xml-file-as-an-element-value-selection. This one has another xml file as lookup while mine's lookup is in another document in the xml file. – schnydszch Jul 28 '15 at 21:23

1 Answers1

1

I am purely guessing here, but perhaps you might use this as your starting point:

XML

<root xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:skos="http://example.com/skos" xmlns:ns0="http://example.com/ns0">
  <rdf:RDF xmlns:xsl="http://www.w3.org/1999/02/22-rdf-syntax-ns#">

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

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

  </rdf:RDF>
</root>

XSLT 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://example.com/skos" 
xmlns:ns0="http://example.com/ns0">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:key name="resource-by-page" match="ns0:isUsedAs" use="substring-after(@rdf:resource, '/page/')" />

<xsl:template match="/root">
    <output>
        <xsl:for-each select="rdf:RDF/skos:Concept">
            <xsl:variable name="page" select="substring-after(@rdf:about, '/page/')" />
            <xsl:variable name="resource" select="key('resource-by-page', $page)/@rdf:resource" />
            <xsl:variable name="lang" select="substring-before(substring-after($resource, 'http://aims.fao.org/skosmos/agrovoc/'), '/page/')" />
            <page>
                <xsl:value-of select="$page" />
            </page>
            <resource>
                <xsl:value-of select="$resource" />
            </resource>
            <lang>
                <xsl:value-of select="$lang" />
            </lang>
            <label>
                <xsl:value-of select="skos:prefLabel[@xml:lang=$lang]" />
            </label>
        </xsl:for-each>
    </output>
</xsl:template>

</xsl:stylesheet>

Result

<?xml version="1.0" encoding="UTF-8"?>
<output xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:skos="http://example.com/skos" xmlns:ns0="http://example.com/ns0">
   <page>c_1591</page>
   <resource>http://aims.fao.org/skosmos/agrovoc/en/page/c_1591</resource>
   <lang>en</lang>
   <label>christmas trees</label>
</output>

What this does is:

  1. Start at skos:Concept and extract the page number ("c_1591") from the rdf:about attribute;
  2. Find the ns0:isUsedAs element with a matching page number;
  3. Extract the language code ("en") from the rdf:resource attribute;
  4. Find the skos:prefLabel child of the current skos:Concept that has the matching language code;
  5. Get the label.
michael.hor257k
  • 113,275
  • 6
  • 33
  • 51
  • Thanks for this. I'll try this. I've already added my namespaces – schnydszch Jul 24 '15 at 13:38
  • I've edited again the question and added another node tree Skos concept with child nodes skos:prefLabel and skos:broader. I've also added Skos:concept before the ns0:isUsedAs to show that it is a separate node tree and not actually hierarchical with skos:Concept rdf:about="http://aims.fao.org/skosmos/agrovoc/en/page/c_1591" which has a child christmas trees I hope I make clear my question. Thanks! – schnydszch Jul 24 '15 at 14:16