relpipe-data/examples/relpipe-in-sparql.xsl
branchv_0
changeset 310 aeda3cb4528d
equal deleted inserted replaced
309:71a627e72815 310:aeda3cb4528d
       
     1 <?xml version="1.0" encoding="UTF-8"?>
       
     2 <!--
       
     3 Relational pipes
       
     4 Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info)
       
     5 
       
     6 This program is free software: you can redistribute it and/or modify
       
     7 it under the terms of the GNU General Public License as published by
       
     8 the Free Software Foundation, version 3 of the License.
       
     9 
       
    10 This program is distributed in the hope that it will be useful,
       
    11 but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
       
    13 GNU General Public License for more details.
       
    14 
       
    15 You should have received a copy of the GNU General Public License
       
    16 along with this program. If not, see <http://www.gnu.org/licenses/>.
       
    17 -->
       
    18 <xsl:stylesheet version="1.0"
       
    19 				xmlns="tag:globalcode.info,2018:relpipe"
       
    20 				xmlns:sparql="http://www.w3.org/2005/sparql-results#"
       
    21 				xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
       
    22 				xmlns:fn="http://www.w3.org/2005/xpath-functions"
       
    23 				xmlns:xs="http://www.w3.org/2001/XMLSchema"
       
    24 				exclude-result-prefixes="fn sparql xs">
       
    25 	<xsl:output
       
    26 		method="xml"
       
    27 		indent="yes"
       
    28 		encoding="UTF-8"/>
       
    29 
       
    30 	<xsl:param name="relation" select="'rdf'"/>
       
    31 
       
    32 	<xsl:template match="/sparql:sparql">
       
    33 		<relpipe>
       
    34 			<relation>
       
    35 				<name>
       
    36 					<xsl:value-of select="$relation"/>
       
    37 				</name>
       
    38 				<attributes-metadata>
       
    39 					<xsl:for-each select="sparql:head/sparql:variable">
       
    40 						<attribute-metadata name="{@name}" type="string"/>
       
    41 						<!-- here we can optionally append additional attributes with some metadata -->
       
    42 					</xsl:for-each>
       
    43 				</attributes-metadata>
       
    44 				
       
    45 				<xsl:for-each select="sparql:results/sparql:result">
       
    46 					<xsl:variable name="record" select="."/>
       
    47 					<record>
       
    48 						<xsl:for-each select="/sparql:sparql/sparql:head/sparql:variable">
       
    49 							<xsl:variable name="attribute" select="@name"/>
       
    50 							<xsl:call-template name="record">
       
    51 								<xsl:with-param name="record" select="$record"/>
       
    52 								<xsl:with-param name="attribute" select="$attribute"/>
       
    53 							</xsl:call-template>
       
    54 						</xsl:for-each>
       
    55 					</record>
       
    56 				</xsl:for-each>
       
    57 				
       
    58 			</relation>
       
    59 		</relpipe>
       
    60 	</xsl:template>
       
    61 	
       
    62 	<xsl:template name="record">
       
    63 		<xsl:param name="record"/>
       
    64 		<xsl:param name="attribute"/>
       
    65 		<attribute>
       
    66 			<xsl:value-of select="$record/sparql:binding[@name=$attribute]"/>
       
    67 			<!-- here we can optionally append additional attributes with some metadata -->
       
    68 			<!--
       
    69 				<sparql:binding name="…attribute…">
       
    70 					<sparql:uri>…value…</sparql:uri>
       
    71 					<sparql:literal xml:lang="it">…value…</sparql:literal>
       
    72 				</sparql:binding>
       
    73 			-->
       
    74 		</attribute>
       
    75 	</xsl:template>
       
    76 
       
    77 </xsl:stylesheet>