add xslt transformation
authorJakub Jaszczynski <j.j.jaszczynski@gmail.com>
Thu, 19 Aug 2010 06:48:18 +0000 (08:48 +0200)
committerJakub Jaszczynski <j.j.jaszczynski@gmail.com>
Thu, 19 Aug 2010 06:48:18 +0000 (08:48 +0200)
data/dicts/eng-us.xdxf
trunk/src/base/base.pro
trunk/src/base/gui/TranslationWidget.cpp
trunk/src/base/gui/TranslationWidget.h
trunk/src/base/xsl.xsl [new file with mode: 0644]
trunk/src/base/xslt2.qrc [new file with mode: 0644]
trunk/src/plugins/xdxf/src/TranslationXdxf.cpp
trunk/src/plugins/xdxf/src/xdxfplugin.cpp

index 220c3e3..dc51445 100644 (file)
@@ -10,7 +10,7 @@ Medium Wave</ar>
 <ar><k>Airplane</k>
 Aeroplane</ar>
 <ar><k>Aluminum</k>
-Aluminium</ar>
+Aluminium to text text wiecej tekstu to text text wiecej tekstuto text text wiecej tekstuto text text wiecej tekstuto text text wiecej tekstuto text text wiecej tekstuto text text wiecej tekstuto text text wiecej tekstu</ar>
 <ar><k>Apartment</k>
 Flatlane</ar>
 <ar><k>Appetizer</k>
@@ -301,8 +301,8 @@ Courgette</ar>
 Tartlane</ar>
 <ar><k>airplane</k>
 Aeroplane</ar>
-<ar><k>aluminum</k>
-Aluminium</ar>
+<ar><k>Aluminum</k>
+Aluminium to ala ma kota a kot ma ale Aluminium to ala ma kota a kot ma alAluminium to ala ma kota a kot ma alAluminium to ala ma kota a kot ma al</ar>
 <ar><k>amrtment</k>
 Medium Wave</ar>
 <ar><k>anesthesia</k>
index 03bfb66..d504c20 100644 (file)
@@ -4,7 +4,7 @@
 #
 #-------------------------------------------------
 
-QT       += core gui
+QT       += core gui xmlpatterns xml
 
 maemo5 {
     QT += maemo5
@@ -84,3 +84,5 @@ unix {
   desktop.files += ../../../data/other/$${TARGET}.desktop
   icon64.files += ../../../data/icons/64x64/$${TARGET}.png
 }
+
+RESOURCES += xslt2.qrc
index 22c55c0..fbb68ee 100644 (file)
@@ -34,7 +34,7 @@ TranslationWidget::TranslationWidget(QWidget *parent):
     setWindowFlags(windowFlags() | Qt::Window);
 
     initializeUI();
-
+    //Q_INIT_RESOURCE(xslt);
     setWindowTitle(tr("Translation"));
 }
 
@@ -54,7 +54,12 @@ void TranslationWidget::show(QStringList translations) {
         trans += t + "\n";
     }
 
-    textEdit->setPlainText(trans);
+//    qDebug()<<trans;
+    trans=tr("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>") + tr("\n <ar>") + trans + tr("\n </ar>");
+
+    trans=XslConversion(trans);
+    textEdit->insertHtml(trans);
+  // textEdit->setPlainText(trans);
 
     textEdit->repaint(this->rect());
 
@@ -63,6 +68,24 @@ void TranslationWidget::show(QStringList translations) {
     emit updateSize();
 }
 
+QString TranslationWidget::XslConversion(QString translation)
+{
+    QXmlQuery myQuery(QXmlQuery::XSLT20);
+    myQuery.setFocus(translation);
+//    qDebug()<<translation;
+    QFile file(":/xsl/xsl.xsl");
+    if(!file.open(QFile::ReadOnly)){
+        qDebug()<<"can't open a xslt file";
+        return translation;
+    }
+    QString xslt;
+    xslt=file.readAll();
+    myQuery.setQuery(xslt);
+    QString result("");
+    myQuery.evaluateTo(&result);
+    return result;
+}
+
 void TranslationWidget::initializeUI() {
 
     zoomInToolButton = new QToolButton;
index 0b8f058..e09c8d0 100644 (file)
@@ -30,6 +30,8 @@
 #include <QtGui>
 #include "../backbone/backbone.h"
 #include "TranslationWidgetAutoResizer.h"
+#include <QtXml>
+#include <QXmlQuery>
 
 //! Displays translation of word found in dictionaries
 /*!
@@ -52,6 +54,7 @@ public Q_SLOTS:
 
 
 private:
+    QString XslConversion(QString translation);
     QTextEdit *textEdit;
     QToolButton* zoomInToolButton;
     QToolButton* zoomOutToolButton;
diff --git a/trunk/src/base/xsl.xsl b/trunk/src/base/xsl.xsl
new file mode 100644 (file)
index 0000000..5cd6a73
--- /dev/null
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+<xsl:template match="/">
+       <html>
+       <body>
+       <table border="1" WIDTH="100%">
+       <tr bgcolor="#FF0000">
+               <th><xsl:value-of select="ar/dict[1]/key"/></th>
+       </tr>
+       <xsl:for-each select="ar/dict"> 
+               <tr bgcolor="#9acd32">
+                       <th><xsl:value-of select="info"/></th>
+               </tr>
+               <xsl:for-each select="t">
+                       <tr>
+                       <td><xsl:apply-templates/></td>
+                       </tr>
+               </xsl:for-each> 
+       </xsl:for-each>
+       </table>
+       </body>
+       </html>
+</xsl:template> 
+
+<xsl:template match="tr">
+       [<i><xsl:apply-templates/></i>]
+</xsl:template> 
+
+<xsl:template match="pot">
+       ,<i><xsl:apply-templates/></i>
+</xsl:template>
+
+<xsl:template match="tence">
+       ,<i><xsl:apply-templates/></i>
+</xsl:template>
+
+<xsl:template match="def">
+       ,(<xsl:apply-templates/>)
+</xsl:template>
+
+<xsl:template match="ex">
+       ,"<xsl:apply-templates/>"
+</xsl:template>
+
+<xsl:template match="c">
+       <xsl:variable name="atr" select="@c"/>
+       <font color="{$atr}"> <xsl:apply-templates/> </font>
+</xsl:template>
+
+</xsl:stylesheet> 
diff --git a/trunk/src/base/xslt2.qrc b/trunk/src/base/xslt2.qrc
new file mode 100644 (file)
index 0000000..94c710a
--- /dev/null
@@ -0,0 +1,5 @@
+<RCC>
+    <qresource prefix="/xsl">
+        <file>xsl.xsl</file>
+    </qresource>
+</RCC>
index 1c9fa34..c0ae5d9 100644 (file)
@@ -38,7 +38,11 @@ QString TranslationXdxf::dictionaryInfo() const {
 }
 
 QString TranslationXdxf::toHtml() const {
-    return xdxfPlugin->search(_key);
+    QString result("");
+//    qDebug()<<xdxfPlugin->search(_key);
+    result+="<dict>" + _dictionaryInfo + "<key>" + _key + "</key>"  +xdxfPlugin->search(_key) + "</dict>";
+//    qDebug()<<result;
+    return result;
 }
 
 void TranslationXdxf::setKey(QString _key) {
index fee5602..73c7e5f 100644 (file)
@@ -234,6 +234,7 @@ QString XdxfPlugin::searchFile(QString key) {
     }
     stopped=false;
     dictionaryFile.close();
+
     return resultString;
 }
 
@@ -341,6 +342,8 @@ void XdxfPlugin::getDictionaryInfo() {
     if(reader.name()=="description")
         _infoNote=reader.readElementText();
 
+    _infoNote="<info path=\""+path+"\">"+"\n" + _name + "(" + _type + ")"  + "</info>";
+
     dictionaryFile.close();
 }