<?xml version="1.0" encoding="UTF-8"?>
<!-- $Id: xlink2lil.xsl 488 2007-04-26 02:13:58Z dret $ -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xlink="http://www.w3.org/1999/xlink" exclude-result-prefixes="xlink">
	<xsl:output media-type="xml" indent="yes"/>
	<xsl:param name="context" select="'http://www.ischool.berkeley.edu/~glushko/'"/>
	<xsl:template match="/">
		<links>
			<xsl:for-each select="descendant::*[@xlink:type = 'extended']">
				<xsl:for-each select="*[@xlink:type = 'locator'][@xlink:href = $context or starts-with(@xlink:href, concat($context, '#'))]">
					<!-- the following code does not treat "onLoad" in a special way (which is bad!) -->
					<link start="{@xlink:href}">
						<xsl:if test="../@xlink:title">
							<xsl:attribute name="title">
								<xsl:value-of select="../@xlink:title"/>
							</xsl:attribute>
						</xsl:if>
						<xsl:if test="@xlink:role">
							<xsl:attribute name="role">
								<xsl:value-of select="@xlink:role"/>
							</xsl:attribute>
						</xsl:if>
						<xsl:for-each select="../*[@xlink:type = 'arc'][@xlink:from = current()/@xlink:label]">
							<!-- only create first level entries if there are second level entries (i.e., resources) -->
							<xsl:if test="../*[@xlink:type = 'locator' or @xlink:type = 'resource'][@xlink:label = current()/@xlink:to]">
								<first>
									<xsl:if test="@xlink:title">
										<xsl:attribute name="title">
											<xsl:value-of select="@xlink:title"/>
										</xsl:attribute>
									</xsl:if>
									<xsl:if test="@xlink:arcrole">
										<xsl:attribute name="role">
											<xsl:value-of select="@xlink:arcrole"/>
										</xsl:attribute>
									</xsl:if>
									<xsl:for-each select="../*[@xlink:type = 'locator' or @xlink:type = 'resource'][@xlink:label = current()/@xlink:to]">
										<second>
											<xsl:if test="@xlink:title">
												<xsl:attribute name="title">
													<xsl:value-of select="@xlink:title"/>
												</xsl:attribute>
											</xsl:if>
											<xsl:if test="@xlink:role">
												<xsl:attribute name="role">
													<xsl:value-of select="@xlink:role"/>
												</xsl:attribute>
											</xsl:if>
											<xsl:choose>
												<xsl:when test="@xlink:type = 'locator'">
													<xsl:attribute name="href">
														<xsl:value-of select="@xlink:href"/>
													</xsl:attribute>
												</xsl:when>
												<xsl:otherwise>
													<xsl:value-of select="node()"/>
												</xsl:otherwise>
											</xsl:choose>
										</second>
									</xsl:for-each>
								</first>
							</xsl:if>
						</xsl:for-each>
					</link>
				</xsl:for-each>
			</xsl:for-each>
		</links>
	</xsl:template>
</xsl:stylesheet>