LibreOffice plugin to pipe whole Writer documents through Google Translate, that ought to keep most of the page formatting.

⌈⌋ ⎇ branch:  PageTranslate


Artifact [4597b7ac01]

Artifact 4597b7ac0127581e40efe1b2d6494d78796b9106:

  • File help/en/vnd.include-once.pagetranslate/mallard2xhp.xsl — part of check-in [a2bf060c6d] at 2020-06-10 05:09:11 on branch trunk — Introduce crude help file for config options. (user: mario size: 3719)

<?xml version="1.0" encoding="UTF-8"?><!--
/**
 * api: xslt
 * type: transform
 * title: mallard to xhp
 * description: transform help to openoffice xhp
 * version: 0.2
 *
 * Crude mapping from mallard help file to OpenOffice helpdocument/xhp.
 * Only handles paragraphs, titles, lists, sections. No media/images.
 * And info <link>s are just mapped to type=index or bookmark (type=guide)
 * entries, but type=seealso and href= links in the body kept as is.
 * No help.tree generation obviously.
 *
 */-->
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:m="http://projectmallard.org/1.0/" exclude-result-prefixes="m">

<!-- cfg -->
<xsl:variable name="package" select="'vnd.include-once.pagetranslate'"/>
<xsl:variable name="fileref" select="concat('/help/',$package,'/config.xhp')"/><!-- select="base-uri()" -->
<xsl:output mode="xml" indent="yes"/>

<!-- new document carcass -->
<xsl:template match="/m:page">
  <helpdocument version="1.0">
  <meta>
    <topic id="topic_{generate-id()}" indexer="include" status="PUBLISH">
      <title xml-lang="en" id="title_{generate-id()}"><xsl:value-of select="//m:title"/></title>
      <filename><xsl:value-of select="$fileref"/></filename>
    </topic>
    <history>
      <!--created date="{current-dateTime()}"></created>
      <lastedited date="{current-dateTime()}"></lastedited-->
      <created date="2020-02-02T22:22:22"></created>
      <lastedited date="2020-02-02T22:22:22"></lastedited>
    </history>
  </meta>
  <body>
     <xsl:apply-templates/>
  </body>
  </helpdocument>
</xsl:template>

<!-- paragraphs / sections -->
<xsl:template match="m:p">
  <paragraph id="par_{generate-id()}" role="paragraph" xml-lang="en">
    <xsl:value-of select="."/>
  </paragraph>
</xsl:template>
<xsl:template match="m:title">
  <paragraph id="hd_{generate-id()}" role="heading" level="{count(ancestor::*)}" xml-lang="en">
    <xsl:value-of select="."/>
  </paragraph>
</xsl:template>
<xsl:template match="m:section|m:note">
  <paragraph id="sect_{generate-id()}" role="section" xml-lang="en">
    <xsl:apply-templates/>
  </paragraph>
</xsl:template>

<!-- lists -->
<xsl:template match="m:terms">
  <list id="terms_{generate-id()}" xml-lang="en">
    <xsl:apply-templates/>
  </list>
</xsl:template>
<xsl:template match="m:item">
  <listitem id="item_{generate-id()}" xml-lang="en">
    <paragraph id="hd_{generate-id()}" role="heading" level="6" xml-lang="en"><xsl:value-of select="m:title"/></paragraph>
    <xsl:value-of select="m:p"/>
  </listitem>
</xsl:template>
<xsl:template match="m:list">
  <list bullet="disc" type="ordered">
    <xsl:apply-templates/>
  </list>
</xsl:template>

<!-- meta -->
<xsl:template match="m:link">
<xsl:choose>
  <!-- meta links -->
  <xsl:when test="@type='guide'">
    <bookmark id="bm_{generate-id()}" branch="hid/{$package}:{@xref}" xml-lang="en">
      <bookmark_value><xsl:value-of select="//m:desc"/></bookmark_value>
    </bookmark>
  </xsl:when>
  <xsl:when test="@type='index'">
    <bookmark id="helpindex_{generate-id()}" branch="index" xml-lang="en">
      <bookmark_value><xsl:value-of select="@xref"/></bookmark_value>
    </bookmark>
  </xsl:when>
  <!-- body links -->
  <xsl:when test="@type='seealso'">
    <link href="{@xref}"><xsl:value-of select="."/></link>
  </xsl:when>
  <xsl:when test="@href">
    <link href="{@href}"><xsl:value-of select="."/></link>
  </xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template match="m:info">
    <xsl:apply-templates match="m:link"/>
</xsl:template>

<!-- remove all else -->
<xsl:template match="*">
  <xsl:comment>xsl:skipped=<xsl:value-of select="concat('&lt;', name(), '&gt;')"/></xsl:comment>
</xsl:template>

</xsl:stylesheet>