1
/***************************************************************************
2
* Copyright (C) 2004-2009 by Thomas Fischer *
3
* fischer@unix-ag.uni-kl.de *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19
***************************************************************************/
20
#include <libxml/parser.h>
21
#include <libxml/tree.h>
22
#include <libxml/xmlstring.h>
23
#include <libxslt/transform.h>
24
#include <libxslt/xsltutils.h>
29
#include "xsltransform.h"
34
XSLTransform::XSLTransform( const QString& xsltFilename )
36
m_xlstStylesheet = xsltParseStylesheetFile(( const xmlChar* ) xsltFilename.latin1() );
37
if ( m_xlstStylesheet == NULL )
38
qDebug( "Could not load XSLT file '%s'.", xsltFilename.latin1() );
41
XSLTransform::~XSLTransform()
43
xsltFreeStylesheet( m_xlstStylesheet );
46
QString XSLTransform::transform( const QString& xmlText )
48
QString result = QString::null;
49
QCString xmlCText = xmlText.utf8();
50
xmlDocPtr document = xmlParseMemory( xmlCText, xmlCText.length() );
53
if ( m_xlstStylesheet )
55
xmlDocPtr resultDocument = xsltApplyStylesheet( m_xlstStylesheet, document, NULL );
58
// Save the result into the QString
61
xmlDocDumpMemoryEnc( resultDocument, &mem, &size, "UTF-8" );
62
result = QString::fromUtf8( QCString(( char * )( mem ), size + 1 ) );
65
xmlFreeDoc( resultDocument );
68
qDebug( "Applying XSLT stylesheet to XML document failed" );
71
qDebug( "XSLT stylesheet is not available or not valid" );
73
xmlFreeDoc( document );
76
qDebug( "XML document is not available or not valid" );