I’m having some issues with incorrect XSLT transformation. My task is to convert an XML file to an RDF file using XSLT. Therefore, I’d have to create a <rdf:RDF> node with the relevant namespaces, as the root of the XML document. There are two problems in the output:
- The exclude-result-prefixes isn’t working.
- The formatting is horrible. For instance, the
<rdf:RDF>node comes immediately after the XML declaration, and things aren’t being spaced correctly.
It does validate as RDF, though. So at least my syntax on that side is correct.
XSLT:
This is what my XSLT file looks like (other templates snipped, but I can provide full code if necessary). The only thing I can think of that could possibly be relevant is that in the templates that come afterwards I’m using <xsl:element> and <xsl:attribute> instead of directly typing in the node’s code.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
exclude-result-prefixes="fD"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fD="http://www.alunos.dcc.fc.up.pt/~up090316041/footData"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:fD="http://www.alunos.dcc.fc.up.pt/~up090316041/footData/"
xml:base="http://www.alunos.dcc.fc.up.pt/~up090316041/footData/">
<rdfs:Class rdf:ID="Equipa"/>
<rdfs:Class rdf:ID="Treinador"/>
<rdfs:Class rdf:ID="Jogador"/>
<xsl:apply-templates/>
</rdf:RDF>
</xsl:template>
</xsl:stylesheet>
Generated RDF
<?xml version="1.0" encoding="UTF-8"?><rdf:RDF xml:base="http://www.alunos.dcc.fc.up.pt/~up090316041/footData/" xmlns:fD="http://www.alunos.dcc.fc.up.pt/~up090316041/footData/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<rdfs:Class rdf:ID="Equipa"/>
<rdfs:Class rdf:ID="Treinador"/>
<rdfs:Class rdf:ID="Jogador"/>
<rdf:Description rdf:about="ENG_M_UTD">
<rdf:type>Equipa</rdf:type>
<fD:nome xmlns:fD="http://www.alunos.dcc.fc.up.pt/~up090316041/footData">Manchester United</fD:nome>
<fD:estadio xmlns:fD="http://www.alunos.dcc.fc.up.pt/~up090316041/footData">Old Trafford</fD:estadio>
<fD:pais xmlns:fD="http://www.alunos.dcc.fc.up.pt/~up090316041/footData">Inglaterra</fD:pais>
</rdf:Description>
<rdf:Description rdf:about="POR_NANI">
<rdf:type>Jogador</rdf:type>
<fD:nome xmlns:fD="http://www.alunos.dcc.fc.up.pt/~up090316041/footData">Nani</fD:nome>
<fD:pais xmlns:fD="http://www.alunos.dcc.fc.up.pt/~up090316041/footData">Portugal</fD:pais>
<fD:equipa xmlns:fD="http://www.alunos.dcc.fc.up.pt/~up090316041/footData" resource="ENG_M_UTD"/>
</rdf:Description>
<rdf:Description rdf:about="SPA_DE_GEA">
<rdf:type>Jogador</rdf:type>
<fD:nome xmlns:fD="http://www.alunos.dcc.fc.up.pt/~up090316041/footData">David de Gea</fD:nome>
<fD:pais xmlns:fD="http://www.alunos.dcc.fc.up.pt/~up090316041/footData">Espanha</fD:pais>
<fD:equipa xmlns:fD="http://www.alunos.dcc.fc.up.pt/~up090316041/footData" resource="ENG_M_UTD"/>
</rdf:Description>
<rdf:Description rdf:about="POR_PORTO">
<rdf:type>Equipa</rdf:type>
<fD:nome xmlns:fD="http://www.alunos.dcc.fc.up.pt/~up090316041/footData">FC Porto</fD:nome>
<fD:estadio xmlns:fD="http://www.alunos.dcc.fc.up.pt/~up090316041/footData">Estádio do Dragão</fD:estadio>
<fD:pais xmlns:fD="http://www.alunos.dcc.fc.up.pt/~up090316041/footData">Portugal</fD:pais>
</rdf:Description>
<rdf:Description rdf:about="COL_JAMES">
<rdf:type>Jogador</rdf:type>
<fD:nome xmlns:fD="http://www.alunos.dcc.fc.up.pt/~up090316041/footData">James Rodríguez</fD:nome>
<fD:pais xmlns:fD="http://www.alunos.dcc.fc.up.pt/~up090316041/footData">Colombia</fD:pais>
<fD:equipa xmlns:fD="http://www.alunos.dcc.fc.up.pt/~up090316041/footData" resource="POR_PORTO"/>
</rdf:Description>
</rdf:RDF>
Had to change stuff in Eclipse’s Run settings to get it to indent correctly.