PDA

View Full Version : bug XPath in XSLT?



ixSci
30th July 2009, 14:40
Hello all,

I've the following simple code scratch:

QCoreApplication xApplication(argc, argv);

QXmlQuery xQuery(QXmlQuery::XSLT20);
QBuffer xOriginalContent;
QString xXMLContent = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><folder id=\"0\" name=\"root\" is_expanded=\"false\"></folder>";
xOriginalContent.setData( xXMLContent.toAscii() );
xOriginalContent.open(QBuffer::ReadWrite);
xOriginalContent.reset();

xQuery.setFocus(&xOriginalContent);
QString xRequestString;
xRequestString += "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
"<xsl:stylesheet version=\"2.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">"
" <xsl:template match=\"/\">"
" <xsl:apply-templates/>"
" </xsl:template>"
" <xsl:template match=\"folder\">"
" <folder name=\"{@name}\" id=\"{@id}\" is_expanded=\"{@is_expanded}\">"
" <xsl:copy-of select=\"child::node()\"/>"
" <xsl:if test=\"@id=0\">"
" <folder id=\"1\" name=\"name\"> </folder>"
" </xsl:if>"
" </folder>"
" </xsl:template>"
" <xsl:template match=\"*\">"
" <xsl:copy-of select=\".\"/>"
" </xsl:template>"
"</xsl:stylesheet>";

xQuery.setQuery(xRequestString);
assert(xQuery.isValid());
QBuffer xOutputContent;
xOutputContent.open(QBuffer::ReadWrite);
xOutputContent.reset();
std::string str1(xOriginalContent.data());
xQuery.evaluateTo(&xOutputContent);
xXMLContent = xOutputContent.data() ;
std::string str(xOutputContent.data());

return xApplication.exec();
I expect the following result:

<folder name="root" id="0" is_expanded="false"><folder id="1" name="name"/></folder>
but have the following
<folder name="root" id="" is_expanded=""><folder id="1" name="name"/></folder>
As you can see two of three XPath expressions(<folder name=\"{@name}\" id=\"{@id}\" is_expanded=\"{@is_expanded}\">) weren't executed at all! Does anyone have the experience with such a problem?
All your attempts to help will be appreciated

ixSci
4th August 2009, 09:24
There is no the issue in qt 4.5.2 anymore. Closed