<!-- 
--> 
<!DOCTYPE xsl:stylesheet [
	<!ENTITY e    "http://www.xs4all.nl/~pboot/p01/emblem.xml#" >
	<!ENTITY p01 "http://www.xs4all.nl/~pboot/p01/p01rdf.rdf#" >
	<!ENTITY p01s "http://www.xs4all.nl/~pboot/p01/p01rdfs.rdf#" >
	<!ENTITY rdf  "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
	<!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
]>
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  version="1.0"
  xmlns:saxon="http://icl.com/saxon"
  xmlns:p01s="http://www.xs4all.nl/~pboot/p01/p01rdfs.rdf#"
	xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
  exclude-result-prefixes="saxon p01s rdf"
  extension-element-prefixes="saxon p01s rdf">


<xsl:template match="/">
	<xsl:apply-templates select="//rdf:Description">
		<xsl:with-param name="color" select="'red'"/>
	</xsl:apply-templates>
	<xsl:apply-templates select="//rdf:Description">
		<xsl:with-param name="color" select="'green'"/>
	</xsl:apply-templates>
</xsl:template>

<xsl:template match="rdf:Description">
	<xsl:param name="color"/>
	<xsl:message>rdf:Description</xsl:message>
	<xsl:variable name="type">
		<xsl:choose>
			<xsl:when test="@rdf:type">
				<xsl:value-of select="@rdf:type"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="rdf:type/@rdf:resource"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>
	<xsl:variable name="href">
		<xsl:value-of select="substring-after(@rdf:about,'#')"/>
		<xsl:value-of select="$color"/>
		<xsl:text>.svg</xsl:text>
	</xsl:variable>
	<xsl:if test="$type='&p01s;ImgFrag'">
		<saxon:output method="xml" 
				href="{$href}"
				omit-xml-declaration="no" 
				doctype-public="-//W3C//DTD SVG 1.0//EN"
				doctype-system="http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
			<svg>
				<xsl:variable name="id" select="substring-after(@rdf:about,'#')"/>
				<xsl:variable name="file" select="substring-before(@rdf:about,'#')"/>
	<xsl:message><xsl:value-of select="$id"/></xsl:message>
	<xsl:message><xsl:value-of select="$file"/></xsl:message>
				<xsl:apply-templates select="document($file)//*[@id=$id]">
					<xsl:with-param name="color" select="$color"/>
				</xsl:apply-templates>
			</svg>
		</saxon:output>
	</xsl:if>
</xsl:template>

<xsl:template match="xptr">
	<xsl:param name="color"/>
	<xsl:choose>
		<xsl:when test="contains(@from,'2d')">
			<xsl:message>xptr</xsl:message>
			<xsl:variable name="from1" select="substring-after(substring-after(@from,')'),'(')"/>
			<xsl:variable name="x1" select="substring-before($from1,',')"/>
			<xsl:variable name="from2" select="substring-after($from1,',')"/>
			<xsl:variable name="y1" select="substring-before($from2,')')"/>
			<xsl:variable name="from3" select="substring-after($from2,'(')"/>
			<xsl:variable name="x2" select="substring-before($from3,',')"/>
			<xsl:variable name="from4" select="substring-after($from3,',')"/>
			<xsl:variable name="y2" select="substring-before($from4,')')"/>
			<rect stroke="{$color}" fill="none">
				<xsl:attribute name="x">
					<xsl:choose>
						<xsl:when test="$x1 &lt; $x2">
							<xsl:value-of select="$x1"/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="$x2"/>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:attribute>
				<xsl:attribute name="y">
					<xsl:choose>
						<xsl:when test="$y1 &lt; $y2">
							<xsl:value-of select="$y1"/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="$y2"/>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:attribute>
				<xsl:variable name="height" select="$y1 - $y2"/>
				<xsl:variable name="width"  select="$x1 - $x2"/>
				<xsl:attribute name="height">
					<xsl:choose>
						<xsl:when test="$height &lt; 0">
							<xsl:value-of select="0 - $height"/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="$height"/>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:attribute>
				<xsl:attribute name="width">
					<xsl:choose>
						<xsl:when test="$width &lt; 0">
							<xsl:value-of select="0 - $width"/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="$width"/>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:attribute>
				</rect>
		</xsl:when>
		<xsl:when test="contains(@from,'html-polygon')">
			<polygon stroke="{$color}" fill="none" points="{substring-before(substring-after(substring-after(@from,'html-polygon'),'('),')')}"/>
		</xsl:when>
	</xsl:choose>
</xsl:template>

</xsl:stylesheet>

