Commit 8b1ba4ab authored by Baptiste Montange's avatar Baptiste Montange
Browse files

xslt sections

parents f02f1e91 798a47f5
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:h2m="http://www.utc.fr/hdoc/hdoc_to_mongo">
<xsl:function name="h2m:escape-string">
<xsl:param name="value"/>
"<xsl:value-of select="replace($value, '&quot;', '\\&quot;')"/>"
</xsl:function>
</xsl:stylesheet>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project name="hdoc_to_pdf" basedir="." default="convert">
<!--<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="lib/ant-contrib.jar" />
</classpath>
</taskdef>-->
<!-- Arguments properties -->
<property name="InputPath" location="input" />
<property name="OutputPath" location="output" />
<property name="tmp" location="${basedir}/tmp"/>
<property name="OutputPdfPath" location="${OutputPath}/result.pdf" />
<target name="convert">
<echo message="The value of property of InputPath is ${InputPath}" />
<echo message="The value of property of OutputPath is ${OutputPath}" />
<echo message="The value of property of tmp is ${tmp}" />
<project name="hdoc_to_pdf" basedir="." default="main">
<!-- OS properties -->
<condition property="isMac">
<os family="mac"/>
</condition>
<condition property="isWindows">
<os family="windows"/>
</condition>
<condition property="isUnix">
<os family="unix"/>
</condition>
<!-- Arguments properties -->
<property name="InputPath" location="input"/>
<property name="OutputPath" location="output"/>
<property name="tmp" location="${basedir}/tmp"/>
<property name="OutputPdfPath" location="${OutputPath}/result.pdf"/>
<target name="main" depends="convertMac, convertWindows, convertUnix">
<!--temporary files and folders are deleted-->
<delete dir="${tmp}"/>
<delete file="prepare_hdoc.ant"/>
</target>
<!-- Mac target -->
<target name="convertMac" if="isMac" depends="hdocPreparation">
<!--launches the FS/Java script and get a converted PDF file in the output directory-->
<exec executable="java">
<arg value="-cp"/>
<arg value="lib/core-renderer.jar:lib/iText-2.0.8.jar"/>
<arg value="org.xhtmlrenderer.simple.PDFRenderer"/>
<arg value="${tmp}/final.xhtml"/>
<arg value="${OutputPath}/result.pdf"/>
</exec>
</target>
<!-- Windows target -->
<target name="convertWindows" if="isWindows" depends="hdocPreparation">
<!--launches the FS/Java script and get a converted PDF file in the output directory-->
<exec executable="java">
<arg value="-cp"/>
<arg value="lib/core-renderer.jar;lib/iText-2.0.8.jar"/>
<arg value="org.xhtmlrenderer.simple.PDFRenderer"/>
<arg value="${tmp}/final.xhtml"/>
<arg value="${OutputPath}/result.pdf"/>
</exec>
</target>
<!-- Linux target -->
<target name="convertUnix" if="isUnix">
<!--launches the FS/Java script and get a converted PDF file in the output directory-->
<exec executable="java">
<arg value="-cp"/>
<arg value="lib/core-renderer.jar:lib/iText-2.0.8.jar"/>
<arg value="org.xhtmlrenderer.simple.PDFRenderer"/>
<arg value="${tmp}/final.xhtml"/>
<arg value="${OutputPath}/result.pdf"/>
</exec>
</target>
<target name="hdocPreparation">
<echo message="The value of property of InputPath is ${InputPath}"/>
<echo message="The value of property of OutputPath is ${OutputPath}"/>
<echo message="The value of property of tmp is ${tmp}"/>
<!-- Creation of temp dir -->
<delete dir="${tmp}" failonerror="false"/>
<sleep seconds="1"/>
<mkdir dir="${tmp}"/>
<!-- Get input hdoc file path -->
<fileset id="fileset_hdoc" dir="${InputPath}" casesensitive="yes">
<include name="*.hdoc"/>
</fileset>
<pathconvert property="HdocFile" pathsep="" refid="fileset_hdoc" />
<echo message="Executing conversion..." />
<!-- Unzips the hdoc to be converted-->
<unzip dest="${tmp}" src ="${HdocFile}"/>
<!-- Gives all rights to avoid bugs-->
<chmod dir="${tmp}" perm="777"/>
<!-- Get input hdoc file path -->
<fileset id="fileset_hdoc" dir="${InputPath}" casesensitive="yes">
<include name="*.hdoc"/>
</fileset>
<pathconvert property="HdocFile" pathsep="" refid="fileset_hdoc"/>
<echo message="Executing conversion..."/>
<!-- Unzips the hdoc to be converted-->
<unzip dest="${tmp}" src="${HdocFile}"/>
<!-- Gives all rights to avoid bugs-->
<chmod dir="${tmp}" perm="777"/>
<!--launches the XSLT find_content to retrieve the content path-->
<xslt in="${tmp}/META-INF/container.xml" out="prepare_hdoc.ant" style="xsl/find_content.xsl">
<param name="TempRepository" expression="${tmp}"/>
......@@ -45,17 +94,7 @@
<chmod file="prepare_hdoc.ant" perm="777"/>
<!--launches the ANT prepare_hdoc.ant resulting from the previous XSLT in order to get a clean xhtml ready for the pdf conversion -->
<ant antfile="prepare_hdoc.ant"/>
<!--launches the ANT xxx to execute the FS/Java script and get a converted PDF file in the output directory-->
<!--TODO-->
<!--temporary files and folders are deleted-->
<!--<delete dir="${tmp}"/>-->
<!--<delete file="prepare_hdoc.ant"/>-->
</target>
<ant antfile="prepare_hdoc.ant"/>
</target>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:h="urn:utc.fr:ics:hdoc:container"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
name="hdoc_to_pdf"
default="main">
<target name="main">
<xslt in="/home/raphael/Documents/Travail/NF29/projet/hdoc/hdoc_to_pdf/tmp/content.xml"
out="/home/raphael/Documents/Travail/NF29/projet/hdoc/hdoc_to_pdf/tmp/hdoc_nsless.xhtml"
style="xsl/ns_remover.xsl"/>
<xslt in="/home/raphael/Documents/Travail/NF29/projet/hdoc/hdoc_to_pdf/tmp/hdoc_nsless.xhtml"
out="/home/raphael/Documents/Travail/NF29/projet/hdoc/hdoc_to_pdf/tmp/flat_hdoc.xhtml"
style="xsl/hdoc_flattenizer.xsl"/>
</target>
</project>
......@@ -23,5 +23,6 @@
<xslt in="{$TempRepository}/{$path}" out="{$TempRepository}/hdoc_nsless.xhtml" style="xsl/ns_remover.xsl"/>
<xslt in="{$TempRepository}/hdoc_nsless.xhtml" out="{$TempRepository}/flat_hdoc.xhtml" style="xsl/hdoc_flattenizer.xsl"/>
<xslt in="{$TempRepository}/flat_hdoc.xhtml" out="{$TempRepository}/final.xhtml" style="xsl/last_transformer.xsl"/>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
xpath-default-namespace="http://www.w3.org/1999/xhtml"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.w3.org/1999/xhtml"
>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="html">
<Helloworld/>
<html>
<xsl:apply-templates/>
</html>
</xsl:template>
<xsl:template match="head">
<head>
<xsl:apply-templates select="node()|@*"/>
<link>
<xsl:attribute name="ref">stylesheet</xsl:attribute>
<xsl:attribute name="type">text/css</xsl:attribute>
<xsl:attribute name="href">css/main.css</xsl:attribute>
</link>
</head>
</xsl:template>
<xsl:template match="section">
<xsl:variable name="level" select="count(ancestor::section) + 1"/>
<div>
<xsl:element name="h{$level}">
<xsl:value-of select="header/h1"/>
</xsl:element>
<xsl:apply-templates/>
</div>
</xsl:template>
<xsl:template match="header">
</xsl:template>
<xsl:template match="div">
<xsl:variable name="level" select="count(ancestor::section) + 1"/>
<div>
<xsl:element name="h{$level}">
<xsl:value-of select="h6"/>
</xsl:element>
<xsl:apply-templates/>
</div>
</xsl:template>
<xsl:template match="h6">
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xpath-default-namespace="http://www.w3.org/1999/xhtml">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
......@@ -238,7 +238,58 @@
</xsl:element>
</xsl:element>
</xsl:template>
<!-- QCMs -->
<xsl:template match="node[contains(@TEXT, '#question')]" priority="2">
<xsl:element name="section">
<xsl:element name="header">
<xsl:element name="h1">QCM</xsl:element>
</xsl:element>
<xsl:element name="div">
<xsl:attribute name="data-hdoc-type">question</xsl:attribute>
<xsl:element name="ul">
<xsl:element name="li">
<xsl:element name="p">
<xsl:value-of select="utc:remove-language(@TEXT)"/>
</xsl:element>
</xsl:element>
</xsl:element>
</xsl:element>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<!-- Match the global explanation of of a question within a QCM -->
<xsl:template match="node[contains(@TEXT, '#explanation')]" priority="2">
<xsl:element name="div">
<xsl:attribute name="data-hdoc-type">explanation</xsl:attribute>
<xsl:element name="p">
<xsl:value-of select="utc:remove-language(@TEXT)"/>
</xsl:element>
</xsl:element>
</xsl:template>
<!-- Match the correct answers of a question within a QCM -->
<xsl:template match="node[contains(@TEXT, '#choice-correct')]" priority="2">
<xsl:element name="div">
<xsl:attribute name="data-hdoc-type">choice-correct</xsl:attribute>
<xsl:element name="p">
<xsl:value-of select="utc:remove-language(@TEXT)"/>
</xsl:element>
</xsl:element>
</xsl:template>
<!-- Match the wrong answers of a question within a QCM -->
<xsl:template match="node[contains(@TEXT, '#choice-incorrect')]" priority="2">
<xsl:element name="div">
<xsl:attribute name="data-hdoc-type">choice-incorrect</xsl:attribute>
<xsl:element name="p">
<xsl:value-of select="utc:remove-language(@TEXT)"/>
</xsl:element>
</xsl:element>
</xsl:template>
<!-- Default behavior for intro and conclu nodes : do nothing -->
<xsl:template match="node[contains(@TEXT, '#intro')] | node[contains(@TEXT, '#conclu')]"
priority="3"/>
......@@ -251,7 +302,7 @@
<xsl:function name="utc:remove-language" as="xs:string">
<xsl:param name="text" as="xs:string?"/>
<xsl:variable name="text2" select="string($text)"/>
<xsl:value-of select="replace($text2, '(#[0-9a-z]* )+', '')"/>
<xsl:value-of select="replace($text2, '(#[0-9a-z|-]* )+', '')"/>
</xsl:function>
</xsl:stylesheet>
......@@ -149,3 +149,11 @@ The opale_to_hdoc converter transcribes an Opale publication to a hdoc format. O
The source code converter is available and can be completed in order to
improve it and manage more Opale elements.
Modified by Benoit Villain (12/12/2016)
------------------
Les divisions et les parties d'un grain n'étaient pas traitées... Contrairement à ce que mentionne le README...
J'ai donc apporté les modifications nécessaires pour que les divisions et les parties (récursives) soient bel et bien transformées en "section" hdoc.
This diff is collapsed.
......@@ -423,8 +423,10 @@
<xsl:template match="div[@id='toctitle']/h2" priority="1"/>
<!-- Ignoring end of file h2: see also, etc... -->
<xsl:template match="h2[not(following-sibling::p intersect following-sibling::h2[1]/preceding-sibling::p)]"/>
<!-- <xsl:template match="h2[not(following-sibling::p intersect following-sibling::h2[1]/preceding-sibling::p)]"/>-->
<xsl:template match=" h2[following-sibling::ul[li/a[@class='external text'] and preceding-sibling::h2]][last()]"/>
<xsl:template match=" h2[following-sibling::div[@class='references-small decimal'] and preceding-sibling::h2][last()]"/>
<xsl:template match="div[@id='mw-navigation']/h2"/>
<!-- Ignoring divs by default: they are not relevant to us -->
<xsl:template match="div" mode="#all"/>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment