[octc-svndiff] SF.net SVN: octc:[416] trunk/tools/xsl/octc2vm.xsl
Brought to you by:
bansp
|
From: <ba...@us...> - 2010-11-25 03:22:47
|
Revision: 416
http://octc.svn.sourceforge.net/octc/?rev=416&view=rev
Author: bansp
Date: 2010-11-25 03:22:41 +0000 (Thu, 25 Nov 2010)
Log Message:
-----------
abuse the critical apparatus tagset to display alignment information...
Added Paths:
-----------
trunk/tools/xsl/octc2vm.xsl
Added: trunk/tools/xsl/octc2vm.xsl
===================================================================
--- trunk/tools/xsl/octc2vm.xsl (rev 0)
+++ trunk/tools/xsl/octc2vm.xsl 2010-11-25 03:22:41 UTC (rev 416)
@@ -0,0 +1,163 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xpath-default-namespace="http://www.tei-c.org/ns/1.0" xmlns:tei="http://www.tei-c.org/ns/1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xd="http://www.pnp-software.com/XSLTdoc" xmlns:f="func" exclude-result-prefixes="xs xd f tei" version="2.0">
+
+ <xsl:output doctype-system="../src/tei_all.dtd" method="xml" indent="yes"/>
+
+ <xd:doc type="stylesheet">
+ <xd:short>octc2vm: converts OCTC aligned documents into the <a href="http://www.v-machine.org/">Versioning Machine</a> format.</xd:short>
+ <xd:detail>
+ <p>It abuses the critical apparatus tagset for displaying parallel alignment information.</p>
+ <p>It's rather kludgy now... some routines should be externalized and imported to here and octc2tmx</p>
+ </xd:detail>
+ <xd:author>Piotr Bański</xd:author>
+ <xd:copyright>the author(s), 2010; license: GPL v3 or any later version (http://www.gnu.org/licenses/gpl.html).</xd:copyright>
+ <xd:svnId>$Id:$</xd:svnId>
+ </xd:doc>
+
+
+ <xd:doc>The current version of the script, set automatically by SVN.</xd:doc>
+ <xsl:variable name="version" select="'$Rev$'" as="xs:string"/>
+
+ <xsl:variable name="langs" as="xs:string+" select="/teiCorpus/teiCorpus/TEI/text/body/div[@type='doc']/linkGrp/ptr/@xml:lang"/>
+
+
+<xsl:template match="/">
+ <xsl:variable name="root" as="node()" select="."/>
+ <xsl:processing-instruction name="xml-stylesheet">href="../src/vmachine.xsl" type="text/xsl"</xsl:processing-instruction>
+ <TEI xmlns="http://www.tei-c.org/ns/1.0">
+ <teiHeader>
+ <fileDesc>
+ <titleStmt>
+ <title>Parallel alignment visualization thingy</title>
+<!-- <author>and by</author>-->
+ <respStmt>
+ <resp>abused by Piotr</resp>
+ <name/>
+ </respStmt>
+ </titleStmt>
+ <publicationStmt>
+ <availability>
+ <p>Available under GNU GPL 3.0</p>
+ </availability>
+ </publicationStmt>
+ <sourceDesc>
+ <p>OCTC aligned subcorpus</p>
+ </sourceDesc>
+ </fileDesc>
+ <encodingDesc>
+ <projectDesc>
+ <p>An attempt to see if we can use the Versioning Machine to show alignments. Note that it's possible to use this with more than two languages.</p>
+ </projectDesc>
+ <variantEncoding location="internal" method="parallel-segmentation"/>
+ </encodingDesc>
+ </teiHeader>
+ <text>
+ <front>
+ <div>
+ <listWit>
+ <xsl:for-each select="$langs">
+ <witness xml:id="{.}">
+ <xsl:variable name="part1" select="$root/teiCorpus/teiCorpus/teiHeader/profileDesc/langUsage/language[@ident eq current()]" as="node()"></xsl:variable>
+ <xsl:value-of select="string-join($part1/name[@xml:lang = $langs],'/')"/>
+ </witness>
+ </xsl:for-each>
+ </listWit>
+ </div>
+ </front>
+ <body>
+ <head>
+ <title>
+ <app>
+ <xsl:for-each select="$langs">
+ <rdg wit="{concat('#',.)}">
+ <xsl:variable name="part1" select="document($root/teiCorpus/teiCorpus/TEI/text/body/div[@type='doc']/linkGrp/ptr[@xml:lang eq current()]/@target)/teiCorpus/teiCorpus/TEI/teiHeader/fileDesc/titleStmt" as="node()"/>
+ <xsl:value-of select="$part1/(title[@xml:lang eq current()] | title[1])[1] (:$root/teiCorpus/teiCorpus/TEI/teiHeader/(title[@xml:lang eq current()] | title[1])[1]:)"/>
+ </rdg>
+ </xsl:for-each>
+ </app>
+ </title>
+ </head>
+ <lg>
+ <xsl:apply-templates select="/teiCorpus/teiCorpus/TEI/text/body/div[@type='doc']"/>
+ </lg>
+ </body>
+ </text>
+ </TEI>
+</xsl:template>
+
+ <xd:doc>Process div elements containing potential translation units. ('tu' is a term from the TMX specification). All this template does is redirect to another template that performs recursive processing of linkGrp elements.</xd:doc>
+ <xsl:template match="div">
+ <xsl:call-template name="process_linkGrp">
+ <xsl:with-param name="node" select="linkGrp" as="node()+"/>
+ </xsl:call-template>
+ </xsl:template>
+
+ <xd:doc>Recursively process linkGrp elements. If there is a div that completely partitions the linkGrp that we are thinking of processing, abandon the linkGrp and process the contents of the div. Repeat. If the processed div is org="uniform" (refer to the wiki for explanation), look for partitioning divs right after the processed linkGrps; if not, look at the ptr/@type="part" elements and work from there.</xd:doc>
+ <xsl:template name="process_linkGrp">
+ <xsl:param name="node" as="node()+"/>
+
+ <xsl:for-each select="$node">
+ <xsl:variable name="partitioning_divs" as="element()*">
+ <xsl:choose>
+ <xsl:when test="ancestor::div[1][count(@org) and @org eq 'uniform']">
+ <xsl:variable name="f_lG" select="following-sibling::linkGrp[1]"/>
+ <xsl:sequence select="following-sibling::div[. << $f_lG][substring(@prev,2) eq current()/@xml:id][@part eq 'N']"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:sequence select="if (count(ptr[@type = 'part'])) then id(substring(ptr[@type = 'part']/@target,2)) else ()"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <xsl:variable name="curr" select="."/>
+
+ <xsl:choose>
+ <xsl:when test="exists($partitioning_divs)">
+ <xsl:for-each select="$partitioning_divs">
+ <xsl:call-template name="process_linkGrp">
+ <xsl:with-param name="node" select="./linkGrp"/>
+ </xsl:call-template>
+ </xsl:for-each>
+ </xsl:when>
+ <xsl:otherwise>
+ <!-- the name here must depend on the granularity of the alignment info -->
+ <xsl:element namespace="http://www.tei-c.org/ns/1.0" name="l">
+ <xsl:attribute name="n" select="substring-before(substring-after(@xml:id,'aln_'),'-linkGrp')"/>
+ <xsl:element name="app" namespace="http://www.tei-c.org/ns/1.0">
+ <xsl:for-each select="$langs">
+ <xsl:element name="rdg" namespace="http://www.tei-c.org/ns/1.0">
+ <xsl:attribute name="wit" select="concat('#',.)"/>
+ <xsl:value-of select="normalize-space(string-join(f:process($curr/ptr[@xml:lang=current()]/@target, $curr),' '))"/>
+ </xsl:element>
+ </xsl:for-each>
+ </xsl:element>
+ </xsl:element>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:for-each>
+ </xsl:template>
+
+ <xd:doc>Dive into each node. The nodes accessed by resolving the URIs may have other nodes embedded within them. These have to be processed separately (string-joined) from multiple siblings (which are string-joined with a space). This function handles embedded q elements, for example.</xd:doc>
+ <xsl:function name="f:process" as="xs:string+">
+ <xsl:param name="targ" as="xs:string+"/>
+ <xsl:param name="context" as="node()"/>
+ <xsl:variable name="node" as="node()*" select="document($targ, $context)"/>
+ <xsl:choose>
+ <xsl:when test="exists($node)">
+ <xsl:for-each select="$node">
+ <xsl:variable name="seq" as="xs:string*">
+ <xsl:apply-templates select="."/>
+ </xsl:variable>
+ <xsl:value-of select="string-join($seq,'')"/>
+ </xsl:for-each>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="('[ERROR: NO MATCH]')"/>
+ </xsl:otherwise>
+ </xsl:choose>
+
+ </xsl:function>
+
+
+
+</xsl:stylesheet>
\ No newline at end of file
Property changes on: trunk/tools/xsl/octc2vm.xsl
___________________________________________________________________
Added: svn:keywords
+ Author URL Rev Date Id
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|