<!-- Outreach Plugin for WordPress, version 2, "Wrong Way 2" -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:is="http://libertini.net/libertus/outreach">

<!--	uri Outreach
			<em>I do declare</em>, that this here text refers to this here webpage -->
<xsl:template match="is:uri">
  <xsl:copy>
    <xsl:apply-templates select="@*"/>
		<xsl:element name="a">
			<xsl:attribute name="class">outreach</xsl:attribute>
			<xsl:attribute name="rel">uri</xsl:attribute>
			<xsl:attribute name="href">
				<xsl:choose>
					<xsl:when test="@cite"><xsl:value-of select="@cite"/></xsl:when>
					<xsl:otherwise><xsl:value-of select="text()"/></xsl:otherwise>
				</xsl:choose>
			</xsl:attribute>
			<xsl:value-of select="."/>
		</xsl:element>
	</xsl:copy>
</xsl:template>

<!--	thing Outreach
			place Outreach
			<em>I do declare</em>, that this here text refers to this here thing
				or place and this here link is how I would learn more about it. -->
<xsl:template match="is:thing|is:place">
  <xsl:copy>
    <xsl:apply-templates select="@*"/>
		<xsl:element name="a">
			<xsl:attribute name="class">outreach</xsl:attribute>
			<xsl:attribute name="rel"><xsl:value-of select="substring-after(name(),':')"/></xsl:attribute>
			<xsl:attribute name="href">
				<xsl:choose>
					<xsl:when test="@from"><xsl:value-of select="@from"/></xsl:when>
					<xsl:otherwise>
						<xsl:text>http://en.wikipedia.org/wiki/</xsl:text>
						<xsl:choose>
							<xsl:when test="@cite"><xsl:value-of select="translate(@cite,' ','_')"/></xsl:when>
							<xsl:otherwise><xsl:value-of select="translate(normalize-space(text()),' ','_')"/></xsl:otherwise>
						</xsl:choose>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:attribute>
			<xsl:value-of select="."/>
		</xsl:element>
	</xsl:copy>
</xsl:template>

<!--	concept Outreach
			person Outreach
			product Outreach
			corp Outreach
			<em>I do declare</em>, that this here text refers to this here concept,
				person, product or corporation. If you want to learn more, Google
				will take you there, unless my link is better. -->
<xsl:template match="is:concept|is:person|is:product|is:corp">
  <xsl:copy>
    <xsl:apply-templates select="@*"/>
		<xsl:element name="a">
			<xsl:attribute name="class">outreach</xsl:attribute>
			<xsl:attribute name="rel"><xsl:value-of select="substring-after(name(),':')"/></xsl:attribute>
			<xsl:attribute name="href">
				<xsl:choose>
					<xsl:when test="@from"><xsl:value-of select="@from"/></xsl:when>
					<xsl:otherwise>
						<xsl:text>http://www.google.com/search?btnI=I'm feeling lucky&amp;q=</xsl:text>
						<xsl:choose>
							<xsl:when test="@cite"><xsl:value-of select="@cite"/></xsl:when>
							<xsl:otherwise><xsl:value-of select="normalize-space(text())"/></xsl:otherwise>
						</xsl:choose>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:attribute>
			<xsl:value-of select="."/>
		</xsl:element>
	</xsl:copy>
</xsl:template>


<!--	search Outreach
				<em>I do declare</em>, that this here text refers to this here search.
				I hope you find what you need. I probably didn't.

			word Outreach
				<em>I do declare</em>, that this is a real word and I know what it means.
				If you don't believe me, here's a link to the dictionary definition! -->
<xsl:template match="is:search|is:word">
  <xsl:copy>
    <xsl:apply-templates select="@*"/>
		<xsl:element name="a">
			<xsl:attribute name="class">outreach</xsl:attribute>
			<xsl:attribute name="rel"><xsl:value-of select="substring-after(name(),':')"/></xsl:attribute>
			<xsl:attribute name="href">
				<xsl:choose>
					<xsl:when test="@from"><xsl:value-of select="@from"/></xsl:when>
					<xsl:otherwise>
						<xsl:text>http://www.google.com/search?q=</xsl:text>
						<xsl:if test="name()='is:word'"><xsl:text>define:</xsl:text></xsl:if>
						<xsl:choose>
							<xsl:when test="@cite"><xsl:value-of select="@cite"/></xsl:when>
							<xsl:otherwise><xsl:value-of select="normalize-space(text())"/></xsl:otherwise>
						</xsl:choose>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:attribute>
			<xsl:value-of select="."/>
		</xsl:element>
	</xsl:copy>
</xsl:template>


<!-- identity transformation, copy all input nodes to output -->
<xsl:template match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>
