<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:lib="http://my.library/rdf/syntax#">

<xsl:template match="/rdf:RDF">
	<library>
		<xsl:apply-templates select="lib:book"/>
	</library>
</xsl:template>

<xsl:template match="lib:author">
	<xsl:variable name="resource" select="@rdf:resource"/>
	<xsl:copy-of select="/rdf:RDF/lib:author[@rdf:about=$resource]"/>
</xsl:template>

<xsl:template match="lib:character">
	<xsl:variable name="resource" select="@rdf:resource"/>
	<xsl:copy-of select="/rdf:RDF/lib:character[@rdf:about=$resource]"/>
</xsl:template>

<xsl:template match="*|@*">
	<xsl:copy>
		<xsl:apply-templates/>
	</xsl:copy>
</xsl:template>

</xsl:stylesheet>