Xml xslt—如何针对另一个节点测试一个节点,并仅接收测试为阳性的节点的输出

Xml xslt—如何针对另一个节点测试一个节点,并仅接收测试为阳性的节点的输出,xml,xslt,Xml,Xslt,我正在创建一个XSLT,它将RDF模式转换为HTML。我试图将某些受控词汇表与其对应的RDF类进行匹配。到目前为止,这些尝试都没有结果 以下是RDF模式的示例: <?xml version="1.0"?> <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:aps=

我正在创建一个XSLT,它将RDF模式转换为HTML。我试图将某些受控词汇表与其对应的RDF类进行匹配。到目前为止,这些尝试都没有结果

以下是RDF模式的示例:

    <?xml version="1.0"?>
<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:aps="rdf_apsSchema.rdf#"
    xml:base="rdf_apsSchema.rdf#">

    <rdfs:Class rdf:ID="ParentID">
        <rdfs:label xml:lang="en">Parent Identifier</rdfs:label>
        <rdfs:comment>A unique identifier for a carrier in which the current carrier was copied
            from</rdfs:comment>
        <rdfs:subClassOf rdf:resource="http://ella.slis.indiana.edu/~shelbyjt/aps/2013-12-17.rdf#ID"
        />
    </rdfs:Class>

    <rdfs:Class rdf:ID="TapeSpeed">
        <rdfs:label xml:lang="en">Tape Speed</rdfs:label>
        <rdfs:comment>The speed in inches per second (IPS) of a tape carrier</rdfs:comment>
    </rdfs:Class>

    <rdfs:Class rdf:ID="TrackConfig">
        <rdfs:label xml:lang="en">Track Configuration</rdfs:label>
        <rdfs:comment>The track configuration of a tape carrier</rdfs:comment>
    </rdfs:Class>

    <aps:TrackConfig rdf:ID="FullTrack"/>
    <aps:TrackConfig rdf:ID="HalfTrackMono"/>
    <aps:TrackConfig rdf:ID="HalfTrackStereo"/>
    <aps:TrackConfig rdf:ID="QuarterTrackMono"/>
    <aps:TrackConfig rdf:ID="QuarterTrackStereo"/>

</rdf:RDF>
预期结果:

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>schema html</title>
    </head>
    <body>
        <table>
            <tr>
                <th>label: </th>
                <td>Parent Identifier</td>
            </tr>
            <tr>
                <th>label: </th>
                <td>Tape Speed</td>
            </tr>
            <tr>
                <th>label: </th>
                <td>Track Configuration</td>
            </tr>
            <tr>
                <th>controlled vocabulary: </th>
            </tr>
        </table>
    </body>
</html>

模式html
标签:
父标识符
标签:
磁带速度
标签:
轨道配置
受控词汇:
当前结果:

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>schema html</title>
    </head>
    <body>
        <table>
            <tr>
                <th>label: </th>
                <td>Parent Identifier</td>
            </tr>
            <tr>
                <th>controlled vocabulary: </th>
            </tr>
            <tr>
                <th>label: </th>
                <td>Tape Speed</td>
            </tr>
            <tr>
                <th>controlled vocabulary: </th>
            </tr>
            <tr>
                <th>label: </th>
                <td>Track Configuration</td>
            </tr>
            <tr>
                <th>controlled vocabulary: </th>
            </tr>
        </table>
    </body>
</html>

模式html
标签:
父标识符
受控词汇:
标签:
磁带速度
受控词汇:
标签:
轨道配置
受控词汇:

我为这篇长篇大论道歉,但我想说得尽可能清楚。如有任何反馈,将不胜感激。谢谢

正如我在评论中所说,这个问题并不清楚。看看这能不能帮你定位。它测试当前类id是否出现在controlledVocab的子元素列表中。如果是,则将包含“正”的表格单元格添加到当前行:

XSLT2.0

<xsl:stylesheet version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xlink="http://www.w3.org/1999/xlink"
    xmlns:aps="rdf_apsSchema.rdf#" 
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">

    <!-- shell for the html -->
    <xsl:template match="/">
        <html xmlns="http://www.w3.org/1999/xhtml">
            <title>schema html</title>
            <body>
                <xsl:apply-templates select="rdf:RDF"/>
            </body>
        </html>
    </xsl:template>

    <!-- sets up the Class Class tables -->
    <xsl:template match="rdf:RDF">
        <table border="1">
            <xsl:apply-templates select="rdfs:Class"/>
        </table>
    </xsl:template>

    <!-- sets up the rdfs:Class transformations -->
    <xsl:template match="rdfs:Class[rdfs:label]">
        <tr>
            <th>label: </th>
            <td><xsl:value-of select="rdfs:label"/></td>
            <!-- this is the problem code -->
            <xsl:if test="@rdf:ID = document('controlledVocab.xml')/controlledVocab/*/name()">
                <td>positive</td>
            </xsl:if>
        </tr>
    </xsl:template>

</xsl:stylesheet>

模式html
标签:
积极的

您是否可以发布controlledVocab.xml文档(或者,最好是其中的一个最小示例)?如果您正在处理RDF,那么您最好使用RDF API(例如Jena),而不是尝试将其作为xml处理。有许多不同的方法可以用XML表示相同的RDF图。@michael.hor257k感谢您的回复。我添加了controlledVocab.xml中的一个示例。@ian roberts我目前只熟悉RDF/xml,但我将研究RDF API。谢谢您确定已发布XSLT示例编译吗?带有布尔比较的select表达式应给出错误。
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>schema html</title>
    </head>
    <body>
        <table>
            <tr>
                <th>label: </th>
                <td>Parent Identifier</td>
            </tr>
            <tr>
                <th>controlled vocabulary: </th>
            </tr>
            <tr>
                <th>label: </th>
                <td>Tape Speed</td>
            </tr>
            <tr>
                <th>controlled vocabulary: </th>
            </tr>
            <tr>
                <th>label: </th>
                <td>Track Configuration</td>
            </tr>
            <tr>
                <th>controlled vocabulary: </th>
            </tr>
        </table>
    </body>
</html>
<xsl:stylesheet version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xlink="http://www.w3.org/1999/xlink"
    xmlns:aps="rdf_apsSchema.rdf#" 
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">

    <!-- shell for the html -->
    <xsl:template match="/">
        <html xmlns="http://www.w3.org/1999/xhtml">
            <title>schema html</title>
            <body>
                <xsl:apply-templates select="rdf:RDF"/>
            </body>
        </html>
    </xsl:template>

    <!-- sets up the Class Class tables -->
    <xsl:template match="rdf:RDF">
        <table border="1">
            <xsl:apply-templates select="rdfs:Class"/>
        </table>
    </xsl:template>

    <!-- sets up the rdfs:Class transformations -->
    <xsl:template match="rdfs:Class[rdfs:label]">
        <tr>
            <th>label: </th>
            <td><xsl:value-of select="rdfs:label"/></td>
            <!-- this is the problem code -->
            <xsl:if test="@rdf:ID = document('controlledVocab.xml')/controlledVocab/*/name()">
                <td>positive</td>
            </xsl:if>
        </tr>
    </xsl:template>

</xsl:stylesheet>