2

我遇到了一些不正确的 XSLT 转换问题。我的任务是使用 XSLT 将 XML 文件转换为 RDF 文件。因此,我必须创建一个<rdf:RDF>具有相关名称空间的节点,作为 XML 文档的根。输出有两个问题:

  1. 排除结果前缀不起作用。
  2. 格式太吓人了 例如,<rdf:RDF>节点紧跟在 XML 声明之后,并且没有正确间隔。

不过,它确实验证为 RDF。所以至少我在那方面的语法是正确的。

XSLT:

这就是我的 XSLT 文件的样子(其他模板被剪掉了,但如果需要我可以提供完整的代码)。我能想到的唯一可能相关的是,在随后我使用的模板中,<xsl:element><xsl:attribute>不是直接输入节点的代码。

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

生成的 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>
4

1 回答 1

0

必须更改 Eclipse 的运行设置中的内容才能正确缩进。

于 2013-01-30T16:51:02.040 回答