Last active
August 29, 2015 14:02
-
-
Save timathom/2e25f9d44d5d4437be83 to your computer and use it in GitHub Desktop.
This file contains 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
(: Group all actors by Act and Scene :) | |
(: XQuery solution :) | |
declare namespace tei="http://www.tei-c.org/ns/1.0"; | |
<results>{ | |
for $actors in //tei:stage/@who | |
for $actor in $actors ! tokenize(., ' ') | |
group by $actor | |
order by $actor | |
return | |
<actor_by_scene>{ | |
<actor>{ substring-after($actor, '#') }</actor>, | |
for $a in $actors | |
let $key := $a/concat(ancestor::tei:div1/@n,'.',ancestor::tei:div2/@n) | |
group by $key | |
order by $key | |
return | |
<act_scene>{ $key }</act_scene> | |
}</actor_by_scene> | |
}</results> | |
(: XSLT solution :) | |
<?xml version="1.0" encoding="UTF-8"?> | |
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" | |
xpath-default-namespace="http://www.tei-c.org/ns/1.0" version="2.0"> | |
<xsl:template match="/"> | |
<results> | |
<xsl:for-each-group select="//stage/@who" group-by="tokenize(.,' ')"> | |
<actor_by_scene> | |
<actor> <xsl:value-of select="substring-after(current-grouping-key(),'#')"/> </actor> | |
<xsl:for-each-group select="current-group()" | |
group-by="concat(ancestor::div1/@n,'.',ancestor::div2/@n)"> | |
<act_scene> <xsl:value-of select="current-grouping-key()"/> </act_scene> | |
</xsl:for-each-group> | |
</actor_by_scene> | |
</xsl:for-each-group> | |
</results> | |
</xsl:template> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment