2

I have this file in .rdf

<rdf:RDF
    xmlns:vitro-public="http://vitro.mannlib.cornell.edu/ns/vitro/public#"
    xmlns:c4o="http://purl.org/spar/c4o/"
    xmlns:ero="http://purl.obolibrary.org/obo/"
    xmlns:pvs="http://vivoweb.org/ontology/provenance-support#"
    xmlns:owl2="http://www.w3.org/2006/12/owl2-xml#"
    xmlns:scirr="http://vivoweb.org/ontology/scientific-research-resource#"
    xmlns:vivo="http://vivoweb.org/ontology/core#"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:bibo="http://purl.org/ontology/bibo/"
    xmlns:afn="http://jena.hpl.hp.com/ARQ/function#"
    xmlns:foaf="http://xmlns.com/foaf/0.1/"
    xmlns:scires="http://vivoweb.org/ontology/scientific-research#"
    xmlns:dcterms="http://purl.org/dc/terms/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
    xmlns:geo="http://aims.fao.org/aos/geopolitical.owl#"
    xmlns:skco="http://www.w3.org/2004/02/skos/core#"
    xmlns:event="http://purl.org/NET/c4dm/event.owl#"
    xmlns:dcelem="http://purl.org/dc/elements/1.1/"
    xmlns:vitro="http://vitro.mannlib.cornell.edu/ns/vitro/0.7#"
    xmlns:vann="http://purl.org/vocab/vann/"
    xmlns:skos="http://www.w3.org/2008/05/skos#"
    xmlns:swvs="http://www.w3.org/2003/06/sw-vocab-status/ns#"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns:fabio="http://purl.org/spar/fabio/"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">

  <rdf:Description rdf:about="http://vivo.iu.edu/individual/n5798">
    <rdf:type rdf:resource="http://vivoweb.org/ontology/core#Project"/>
    <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Kuali Open Library Environment</rdfs:label>
    <vivo:abbreviation>KOLE</vivo:abbreviation>
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
    <vivo:webpage rdf:resource="https://www.kuali.org/ole"/>
    <vivo:dateTimeInterval rdf:resource="http://vivo.iu.edu/individual/n5812339"/>
  </rdf:Description>

  <rdf:Description rdf:about="http://vivo.iu.edu/individual/grant42915">
    <rdf:type rdf:resource="http://vivoweb.org/ontology/core#Grant"/>
    <vivo:totalAwardAmount>12452.7</vivo:totalAwardAmount>
    <vivo:hasFundingVehicle rdf:resource="http://vivo.iu.edu/individual/n5798"/>
  </rdf:Description>

  <rdf:Description rdf:about="http://vivo.iu.edu/individual/n5812339">
    <rdf:type rdf:resource="http://vivoweb.org/ontology/core#DateTimeInterval"/>
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
    <vivo:start rdf:resource="http://vivo.iu.edu/individual/n2359024"/>
    <vivo:end rdf:resource="http://vivo.iu.edu/individual/n2788825"/>
    <vitro:mostSpecificType rdf:resource="http://vivoweb.org/ontology/core#DateTimeInterval"/>
  </rdf:Description>

<rdf:Description rdf:about="http://vivo.iu.edu/individual/n2359024">
    <rdf:type rdf:resource="http://vivoweb.org/ontology/core#DateTimeValue"/>
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
    <vivo:dateTimePrecision rdf:resource="http://vivoweb.org/ontology/core#yearPrecision"/>
    <vivo:dateTime rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2001-01-01T00:00:00</vivo:dateTime>
    <vitro:mostSpecificType rdf:resource="http://vivoweb.org/ontology/core#DateTimeValue"/>
</rdf:Description>

  <rdf:Description rdf:about="http://vivo.iu.edu/individual/n2788825">
    <rdf:type rdf:resource="http://vivoweb.org/ontology/core#DateTimeValue"/>
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
    <vivo:dateTimePrecision rdf:resource="http://vivoweb.org/ontology/core#yearPrecision"/>
    <vivo:dateTime rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2002-02-02T00:00:00</vivo:dateTime>
    <vitro:mostSpecificType rdf:resource="http://vivoweb.org/ontology/core#DateTimeValue"/>
  </rdf:Description>
</rdf:RDF>

And I am using that .xsl sheet

 <?xml version="1.0"?>

<xsl:stylesheet 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"  
xmlns:vivo="http://vivoweb.org/ontology/core#" 
xmlns:foaf="http://xmlns.com/foaf/0.1/" 
xmlns:owl2="http://www.w3.org/2006/12/owl2-xml#" 
xmlns:iuvivo="http://vivo.iu.edu/ontology/iuvivo#" 
version="1.0">

<xsl:output
    method="xml"
    indent="yes"
    omit-xml-declaration="no"
    encoding="utf-8"/>

<xsl:template match="rdf:RDF">

<CERIF  
 xmlns="urn:xmlns:org:eurocris:cerif-1.5-1"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 release="1.5" date="2012-10-17" 
 sourceDatabase="Project Profile">

        <xsl:if test="rdf:Description/rdf:type/@rdf:resource='http://vivoweb.org/ontology/core#Project'">
            <cfProj>
                <cfProjId><xsl:value-of select="rdf:Description/@rdf:about"/></cfProjId>
                <cfAcro><xsl:value-of select="rdf:Description/vivo:abbreviation"/></cfAcro>
                <cfURI><xsl:value-of select="rdf:Description/vivo:webpage //@rdf:resource"/></cfURI>    
                <xsl:if test="rdf:Description/vivo:dateTimeInterval/@rdf:resource=rdf:Description/@rdf:about and rdf:Description/vivo:start/@rdf:resource=rdf:Description/@rdf:about">  
                    <cfStartDate><xsl:value-of select="rdf:Description/vivo:dateTime"/></cfStartDate>
                </xsl:if>
                <xsl:if test="rdf:Description/vivo:dateTimeInterval/@rdf:resource=rdf:Description/@rdf:about and rdf:Description/vivo:end/@rdf:resource=rdf:Description/@rdf:about">    
                    <cfEndDate><xsl:value-of select="rdf:Description/vivo:dateTime"/></cfEndDate>
                </xsl:if>       

                    <cfProj_Class>
                        <cfClassId>0bd2d47a-8688-4758-a63c-45e76825a0f6</cfClassId>                 
                        <cfClassSchemeId>794234b8-25bb-46df-9d26-ae660bca64bc</cfClassSchemeId>
                    </cfProj_Class>

                    <xsl:if test="rdf:Description/vivo:hasFundingVehicle/@rdf:resource=rdf:Description/@rdf:about">
                        <cfProj_Fund>
                            <cfFundId><xsl:value-of select="rdf:Description/@rdf:about"/></cfFundId>                        
                            <cfAmount><xsl:value-of select="rdf:Description/vivo:totalAwardAmount"/></cfAmount> 
                            <cfClassId>eda2b2e6-34c5-11e1-b86c-08000200c9a66</cfClassId>            
                            <cfClassSchemeId>759af93b-34c5-11e1-b86c-0800200c9a66</cfClassSchemeId>
                            </cfProj_Fund>
                            <xsl:if test="rdf:Description/vivo:dateTimeInterval/@rdf:resource=rdf:Description/@rdf:about and rdf:Description/vivo:start/@rdf:resource=rdf:Description/@rdf:about">  
                                <cfStartDate><xsl:value-of select="rdf:Description/vivo:dateTime"/></cfStartDate>
                            </xsl:if>
                            <xsl:if test="rdf:Description/vivo:dateTimeInterval/@rdf:resource=rdf:Description/@rdf:about and rdf:Description/vivo:end/@rdf:resource=rdf:Description/@rdf:about">    
                                <cfEndDate><xsl:value-of select="rdf:Description/vivo:dateTime"/></cfEndDate>
                            </xsl:if>   
                    </xsl:if>   
            </cfProj>
        </xsl:if>   

        <xsl:if test="rdf:Description/rdf:type/@rdf:resource='http://xmlns.com/foaf/0.1/Person'">
            <cfPers>
                <cfPersId><xsl:value-of select="rdf:Description/@rdf:about"/></cfPersId>
                <cfGender><xsl:value-of select="rdf:Description/owl2:gender"/></cfGender>
                <cfURI><xsl:value-of select="rdf:Description/vivo:webpage //@rdf:resource"/></cfURI>
                <cfPersName>
                    <cfFirstNames><xsl:value-of select="concat(rdf:Description/foaf:firstName, ' ', rdf:Description/vivo:middleName)"/></cfFirstNames>\n
                    <cfFamilyNames><xsl:value-of select="rdf:Description/foaf:lastName"/></cfFamilyNames>
                </cfPersName>
                <cfPersKeyw>
                    <cfKeyw><xsl:value-of select="rdf:Description/iuvivo:freetextKeyword"/></cfKeyw>
                </cfPersKeyw>

                    <cfPers_OrgUnit>    
                                <cfClassId>eda2b2e6-34c5-11e1-b86c-08000200c9a66</cfClassId>
                                <cfClassSchemeId>759af93b-34c5-11e1-b86c-0800200c9a66</cfClassSchemeId>
                        <xsl:if test="rdf:Description/vivo:dateTimeInterval/@rdf:resource=rdf:Description/@rdf:about and rdf:Description/vivo:start/@rdf:resource=rdf:Description/@rdf:about">  
                            <cfStartDate><xsl:value-of select="rdf:Description/vivo:dateTime"/></cfStartDate>
                        </xsl:if>
                        <xsl:if test="rdf:Description/vivo:dateTimeInterval/@rdf:resource=rdf:Description/@rdf:about and rdf:Description/vivo:end/@rdf:resource=rdf:Description/@rdf:about">    
                            <cfEndDate><xsl:value-of select="rdf:Description/vivo:dateTime"/></cfEndDate>
                        </xsl:if>   
                    </cfPers_OrgUnit>
            </cfPers>
        </xsl:if>   

        <xsl:if test="rdf:Description/rdf:type/@rdf:resource='http://xmlns.com/foaf/0.1/Organization'">
            <cfOrgUnit>
                <cfOrgId><xsl:value-of select="rdf:Description/@rdf:about"/></cfOrgId>
                <cfAcro><xsl:value-of select="rdf:Description/vivo:abbreviation"/></cfAcro>
                <cfURI><xsl:value-of select="rdf:Description/vivo:webpage //@rdf:resource"/></cfURI>
                <cfOrgKeyw>
                    <cfKeyw><xsl:value-of select="rdf:Description/iuvivo:freetextKeyword"/></cfKeyw>
                </cfOrgKeyw>

                    <cfPers_OrgUnit>    
                                <cfClassId>eda2b2e6-34c5-11e1-b86c-08000200c9a66</cfClassId>
                                <cfClassSchemeId>759af93b-34c5-11e1-b86c-0800200c9a66</cfClassSchemeId>
                        <xsl:if test="rdf:Description/vivo:dateTimeInterval/@rdf:resource=rdf:Description/@rdf:about and rdf:Description/vivo:start/@rdf:resource=rdf:Description/@rdf:about">  
                            <cfStartDate><xsl:value-of select="rdf:Description/vivo:dateTime"/></cfStartDate>
                        </xsl:if>
                        <xsl:if test="rdf:Description/vivo:dateTimeInterval/@rdf:resource=rdf:Description/@rdf:about and rdf:Description/vivo:end/@rdf:resource=rdf:Description/@rdf:about">    
                            <cfEndDate><xsl:value-of select="rdf:Description/vivo:dateTime"/></cfEndDate>
                        </xsl:if>   
                    </cfPers_OrgUnit>

            </cfOrgUnit>
        </xsl:if>

</CERIF>
</xsl:template>
</xsl:stylesheet>

The results I get are this:

<?xml version="1.0" encoding="utf-8"?><CERIF release="1.5" date="2012-10-17" sourceDatabase="Project Profile" xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:iuvivo="http://vivo.iu.edu/ontology/iuvivo#" xmlns:owl2="http://www.w3.org/2006/12/owl2-xml#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:vivo="http://vivoweb.org/ontology/core#" xmlns="urn:xmlns:org:eurocris:cerif-1.5-1">
<cfProj>
<cfProjId>http://vivo.iu.edu/individual/n5798</cfProjId>
<cfAcro>KOLE</cfAcro>
<cfURI>https://www.kuali.org/ole</cfURI>
<cfStartDate>2001-01-01T00:00:00</cfStartDate>
<cfEndDate>2001-01-01T00:00:00</cfEndDate>
<cfProj_Class>
<cfClassId>0bd2d47a-8688-4758-a63c-45e76825a0f6</cfClassId>
<cfClassSchemeId>794234b8-25bb-46df-9d26-ae660bca64bc</cfClassSchemeId>
</cfProj_Class>
<cfProj_Fund>
<cfFundId>http://vivo.iu.edu/individual/n5798</cfFundId>
<cfAmount>12452.7</cfAmount>
<cfClassId>eda2b2e6-34c5-11e1-b86c-08000200c9a66</cfClassId>
<cfClassSchemeId>759af93b-34c5-11e1-b86c-0800200c9a66</cfClassSchemeId>
</cfProj_Fund>
<cfStartDate>2001-01-01T00:00:00</cfStartDate>
<cfEndDate>2001-01-01T00:00:00</cfEndDate>
</cfProj>

There are two things that are not well. First is how I can format the output with the "tabs" define in the .xsl sheet. The second is that some results are not well for example the values in:

1) http://vivo.iu.edu/individual/n5798 has to be http://vivo.iu.edu/individual/grant42915 which is the value in the second "Description" set

2) Both values of 2001-01-01T00:00:00 should be 2002-02-02T00:00:00 which is a value from the 5th set of Description

Thanks a lot

user2973502
  • 29
  • 1
  • 4
  • 1
    Please show the entire stylesheet. If you did, I'd be able to check whether you have simply omitted the following declaration: `` . Then it's nicely formatted - but not necessarily in the way the "tabs " are defined in the stylesheet. – Mathias Müller Nov 18 '13 at 07:40
  • 2
    For processing RDF I would strongly recommend using a proper RDF library such as Sesame rather than trying to process the XML form - there are many different ways to express exactly the same RDF graph in XML. – Ian Roberts Nov 18 '13 at 11:53
  • The problem is that this .xml file follows a standard. So the way the xml file is formatted is important. – user2973502 Nov 18 '13 at 12:15
  • 1
    @IanRoberts's point was that the RDF that you get as _input_ could have lots of different forms (the same RDF data could be represented in lots of different ways in RDF/XML), so using an XSLT transformation is _not_ a reliable way of making sure that you're generating XML in the format that you want. [This answer](http://stackoverflow.com/a/17052385/1281433) talks about some of the danger of using XML tools to read/query/process RDF/XML data. It's about XPath, not XSLT, but the point still stands. – Joshua Taylor Nov 18 '13 at 15:19
  • 1
    To make @IanRoberts's point (and the point of my previous comment) clearer, look at [this RDF/XML](http://pastebin.com/awgz6QFm). It's _exactly_ the same RDF data that you've shown, but the RDF/XML serialization is very different. It contains _exactly_ the same triples, but it's very unlikely that your XSLT will handle it correctly. This is why you should use an RDF library (e.g., Sesame, Jena) to read the RDF and to then construct the XML that you need. You could even generate your own format XML, and then use the XSLT to transform that. You _can't_ depend on the particular XML structure… – Joshua Taylor Nov 18 '13 at 15:24
  • …of your input, because the same RDF data can be serialized in RDF/XML in lots of different ways. – Joshua Taylor Nov 18 '13 at 15:25
  • Well the RDF in this case also follows a standard it always has the same structure. – user2973502 Nov 18 '13 at 15:39

1 Answers1

0

Although Ian Roberts and Joshua Taylor have a point regarding using a RDF library to process the rdf file, if you are sure the RDF will never change then using XSLT is less work. However, if you are not it is better write your own method to write statements (from the RDF library) to XML.

To answer your questions.

  1. The formatting depends on on your XSLTransformer, I use Java's(javax.xml.transform.Transformer) and then I need to set the ident size like this (it might be different for your transformer):

    TransformerFactory factory = TransformerFactory.newInstance();
    Source xslt = new StreamSource(new File("test.xslt"));
    Transformer transformer = factory.newTransformer(xslt);
    transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
    
  2. Retrieving the wrong results. The way your are doing it now is not the correct way to do XSLT. Your select statements can target any of the rdf:Description tags and select the relevant property. If you want to process the projects then you should write a template that matches this property and then process these attributes. Something like this (I'm not entirely sure about your data, so this could be wrong):

    <xsl:template match="rdf:Description">
        <xsl:if test="rdf:type/@rdf:resource='http://vivoweb.org/ontology/core#Project'">
            <cfProj>
                <cfProjId><xsl:value-of select="@rdf:about"/></cfProjId>
    

This will select the rdf:about value of each rdf:Description that has type Project.

Rhand
  • 901
  • 7
  • 20
  • It didnt work. Anyway I could did it. Thanks to all. – user2973502 Nov 23 '13 at 22:34
  • 4
    @user2973502 Do you mean that you found a solution? If you did, you should post it as an answer and mark it as accepted. This is a question and answer site that aims to help not on you (i.e., the original asker) find an answer, but also people who have the same, or similar problems in the future. You may have found an answer on your own, but those people in the future still need one. Please post your solution as an answer and [accept it](http://meta.stackexchange.com/q/5234/225437)! – Joshua Taylor Nov 24 '13 at 04:33