<?xml version="1.0" encoding="UTF-8"?>
<!--
Relational pipes
Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<xsl:stylesheet version="1.0"
xmlns="tag:globalcode.info,2018:relpipe"
xmlns:sparql="http://www.w3.org/2005/sparql-results#"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="fn sparql xs">
<xsl:output
method="xml"
indent="yes"
encoding="UTF-8"/>
<xsl:param name="relation" select="'rdf'"/>
<xsl:template match="/sparql:sparql">
<relpipe>
<relation>
<name>
<xsl:value-of select="$relation"/>
</name>
<attributes-metadata>
<xsl:for-each select="sparql:head/sparql:variable">
<attribute-metadata name="{@name}" type="string"/>
<!-- here we can optionally append additional attributes with some metadata -->
</xsl:for-each>
</attributes-metadata>
<xsl:for-each select="sparql:results/sparql:result">
<xsl:variable name="record" select="."/>
<record>
<xsl:for-each select="/sparql:sparql/sparql:head/sparql:variable">
<xsl:variable name="attribute" select="@name"/>
<xsl:call-template name="record">
<xsl:with-param name="record" select="$record"/>
<xsl:with-param name="attribute" select="$attribute"/>
</xsl:call-template>
</xsl:for-each>
</record>
</xsl:for-each>
</relation>
</relpipe>
</xsl:template>
<xsl:template name="record">
<xsl:param name="record"/>
<xsl:param name="attribute"/>
<attribute>
<xsl:value-of select="$record/sparql:binding[@name=$attribute]"/>
<!-- here we can optionally append additional attributes with some metadata -->
<!--
<sparql:binding name="…attribute…">
<sparql:uri>…value…</sparql:uri>
<sparql:literal xml:lang="it">…value…</sparql:literal>
</sparql:binding>
-->
</attribute>
</xsl:template>
</xsl:stylesheet>