Last active
August 13, 2018 12:53
-
-
Save lguariento/3e7906c72081cd25aa4732806bac8efc to your computer and use it in GitHub Desktop.
Check if a node is empty in external file while transforming a document via xslt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "3.1"; | |
import module namespace templates = "http://exist-db.org/xquery/templates"; | |
declare namespace tei = "http://www.tei-c.org/ns/1.0"; | |
declare option exist:serialize "method=html media-type=text/html"; | |
declare function app:XMLtoHTML($node as node(), $model as map(*)) { | |
let $xml := doc('doc.xml') | |
let $xsl := doc('xmlToHtml.xsl') | |
(: get a list of all the URL parameters that are not either xml= or xslt= :) | |
let $params := | |
<parameters> | |
{ | |
for $p in request:get-parameter-names() | |
let $val := request:get-parameter($p, ()) | |
where not($p = ("document", "directory", "stylesheet")) | |
return | |
<param | |
name="{$p}" | |
value="{$val}"/> | |
} | |
</parameters> | |
return | |
transform:transform($xml, $xsl, $params) | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<?xml-model type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"?> | |
<TEI xmlns="http://www.tei-c.org/ns/1.0" xml:id="myxml"> | |
<teiHeader> | |
</teiHeader> | |
<text> | |
<body> | |
<div> | |
<p><persName ref="pe0001">Bla</persName></p> | |
</div> | |
</body> | |
</text> | |
</TEI> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<TEI xmlns="http://www.tei-c.org/ns/1.0" xml:id="pedb"> | |
<teiHeader> | |
<fileDesc> | |
<titleStmt> | |
<title>Database of persons</title> | |
</titleStmt> | |
<publicationStmt> | |
<ab/> | |
</publicationStmt> | |
<sourceDesc> | |
<ab/> | |
</sourceDesc> | |
</fileDesc> | |
</teiHeader> | |
<text> | |
<body> | |
<listPerson> | |
<person xml:id="pe0001"> | |
<note/> | |
</person> | |
</listPerson> | |
</body> | |
</text> | |
</TEI> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head/> | |
<body> | |
<div class="templates:surround?with=templates/page.html&at=content"> | |
<div data-template="app:XMLtoHTML"/> | |
</div> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<xsl:stylesheet xmlns="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:tei="http://www.tei-c.org/ns/1.0" exclude-result-prefixes="tei" version="3.0"> | |
<xsl:template match="tei:persName"> | |
<xsl:variable name="pedb" select="doc('pedb.xml')"/> | |
<xsl:variable name="peid" select="./@ref"/> | |
<xsl:variable name="note" select="$pedb//tei:person[@xml:id eq $peid]//tei:note"/> | |
<xsl:choose> | |
<xsl:when test="empty($note)"> | |
<xsl:apply-templates/> | |
</xsl:when> | |
<xsl:otherwise> | |
<a href="/pages/hits.html?searchkey={@ref}"> | |
<xsl:apply-templates/> | |
</a> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:template> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment