relpipe-data/makra/sparql-example.xsl
author František Kučera <franta-hg@frantovo.cz>
Mon, 27 Jul 2020 17:51:53 +0200
branchv_0
changeset 310 aeda3cb4528d
permissions -rw-r--r--
examples: Querying an RDF triplestore using SPARQL

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
				xmlns="http://www.w3.org/1999/xhtml"
				xmlns:h="http://www.w3.org/1999/xhtml"
				xmlns:s="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/strana"
				xmlns:k="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/konfigurace"
				xmlns:m="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/makro"
				xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
				xmlns:fn="http://www.w3.org/2005/xpath-functions"
				xmlns:svg="http://www.w3.org/2000/svg"
				xmlns:xs="http://www.w3.org/2001/XMLSchema"
				exclude-result-prefixes="fn h s k m xs">
	
	<!--
		SPARQL example listing
		**********************
		Inserts the listing of a SPARQL query and the listing of result.
		Both files should already exist – the query is not executed by this macro.
		*
		@name base name of the file; .sparql and .txt will be appended
		@result-description optional text (will replace default „Results:“);
		there could be also element m:result-description containing formatted text (including the <p>…</p>)
	-->
	<xsl:template match="m:sparql-example">
		
		<xsl:variable name="source">
			<m:pre jazyk="sparql" src="{@name}.sparql" odkaz="ano"/>
			<xsl:choose>
				<xsl:when test="@result-description">
					<p>
						<xsl:value-of select="@result-description"/>
					</p>
				</xsl:when>
				<xsl:when test="m:result-description">
					<xsl:apply-templates select="m:result-description/*"/>
				</xsl:when>
				<xsl:otherwise>
					<p>Result:</p>
				</xsl:otherwise>
			</xsl:choose>
			<m:pre jazyk="text" src="{@name}.txt"/>
		</xsl:variable>
		
		<xsl:apply-templates select="$source/*"/>
		
	</xsl:template>

</xsl:stylesheet>