在XSLT到RDF中正确格式化/缩进的问题

时间:2012-12-20 19:23:26

标签: xml xslt rdf

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

  1. 排除结果前缀不起作用。
  2. 格式化很糟糕。例如,<rdf:RDF>节点在XML声明之后立即出现,并且事情没有正确间隔。
  3. 验证为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>
    

1 个答案:

答案 0 :(得分:0)

必须在Eclipse的“运行”设置中更改内容以使其正确缩进。