xslt - how to test a node against another node and receive output only for the nodes that tested positive



I am creating an XSLT that will transform an RDF Schema into HTML. I am trying to match certain controlled vocabularies with their corresponding RDF classes. The attempts so far have been unfruitful.


Here's a sample of the RDF schema:



<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://ift.tt/oZyhLL"
xmlns:rdfs="http://ift.tt/177k8UL"
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://ift.tt/1r8Ca4w"
/>
</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>


Here's a sample of the XSLT:



<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsi="http://ift.tt/ra1lAU"
xmlns:xsl="http://ift.tt/tCZ8VR" xmlns:xlink="http://ift.tt/PGV9lw"
xmlns:aps="rdf_apsSchema.rdf#"
xmlns:rdf="http://ift.tt/oZyhLL"
xmlns:rdfs="http://ift.tt/177k8UL">

<!-- shell for the html -->
<xsl:template match="/">
<html xmlns="http://ift.tt/lH0Osb">
<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>
<xsl:apply-templates select="rdfs:Class"/>
</table>
</xsl:template>

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


The problem code (noted in the XSLT) is supposed to test whether <rdfs:Class/@rdf:ID> equals document('controlledVocab.xml')/controlledVocab/* (this file contains the <aps:*> elements with the prefix stripped). When it does, add "the following" to that element's section of the <table>.


Desired result:



<html xmlns="http://ift.tt/lH0Osb">
<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>


Current result:



<html xmlns="http://ift.tt/lH0Osb">
<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>


I apologize for the long post, but I wanted to be as clear as possible. Any feedback would be greatly appreciated. Thanks!


No comments:

Post a Comment