Rakesh Singh
Rakesh Singh

Reputation: 868

Error XTSE0620 : Parse error while parsing xslt string usint QT-XSLT

I am parsing itunes library XML file using xslt grammar.

Here's sample code

 void ITunesMlibParser::createXslForPlistItems(QString &out, int playlistID)
     {

           std::stringstream ss;
         ss <<  "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
         ss <<  "<xsl:stylesheet version=\"2.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" xmlns:fn=\"fn\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">";
         ss <<  "<xsl:output method=\"text\" />";

         ss <<  "<xsl:template match=\"/\">";
        // ss << "<xsl:variable name=\"myplaylist\" select=\"'6711'\"/>";


         ss <<  "<xsl:variable name=\"myplaylist\" select=\"'"<< playlistID <<"'\">" ;

         ss <<  "<xsl:variable name=\"playlist_tracks\" select=\"/plist/dict/array/dict[integer[preceding-sibling::key[1]='Playlist ID']=$myplaylist]/array/dict/integer[preceding-sibling::key[1]='Track ID']\" />";
         ss <<  "<xsl:variable name=\"tracks\" select=\"/plist/dict/dict/dict[integer[preceding-sibling::key[1]='Track ID']=$playlist_tracks]\" />";

         ss <<  "<xsl:for-each select=\"$tracks\">";
         ss <<  "<xsl:value-of select=\"integer[preceding-sibling::key[1]='Track ID']\"/>";
         ss <<  "<xsl:text>,</xsl:text>";
         ss <<  "<xsl:value-of select=\"string[preceding-sibling::key[1]='Name']\"/>";
         ss <<  "<xsl:text>,</xsl:text>";
         ss <<  "<xsl:value-of select=\"integer[preceding-sibling::key[1]='Total Time']\"/>";
         ss <<  "<xsl:text>,</xsl:text>";
         ss <<  "<xsl:value-of select=\"string[preceding-sibling::key[1]='Kind']\"/>";
         ss <<  "<xsl:text>,</xsl:text>";
         ss <<  "<xsl:value-of select=\"string[preceding-sibling::key[1]='Location']\"/>";
         ss <<  "<xsl:text>&#xa;</xsl:text>";
         ss <<  "</xsl:for-each>";
         ss <<  "</xsl:template>";
         ss <<  "</xsl:stylesheet>";
         ss <<  "";

         out = QString::fromStdString(ss.str());         
         return;

 }

Consider below two lines:

 // ss << "<xsl:variable name=\"myplaylist\" select=\"'6711'\"/>";
    ss <<  "<xsl:variable name=\"myplaylist\" select=\"'"<< playlistID <<"'\">" ;

If I hard code Integer value of Playlist = 6711, The parser works. But if I programatically pass an integer value, It gives below error.

Error XTSE0620 line 11, column 190: When attribute select is present on variable, a sequence constructor cannot be used.

// My comment --> line 11 is below or I am not sure if this is guilty line as it works with hard coded value.

<xsl:variable name="playlist_tracks" select="/plist/dict/array/dict[integer[preceding-sibling::key[1]='Playlist ID']=$myplaylist]/array/dict/integer[preceding-sibling::key[1]='Track ID']" />

I am stuck here, and badly need some input from XSLT experts.

Upvotes: 2

Views: 268

Answers (2)

Dimitre Novatchev
Dimitre Novatchev

Reputation: 243549

Consider below two lines:

     // ss << "<xsl:variable name=\"myplaylist\" select=\"'6711'\"/>";     
    ss <<  "<xsl:variable name=\"myplaylist\" select=\"'"<< playlistID <<"'\">" ;

The error is quite obvious: in the second case you don't close the generated <xsl:variable> element.

Must be (note the / at the very end):

ss <<  "<xsl:variable name=\"myplaylist\" select=\"'"<< playlistID <<"'\"/>" ;

Upvotes: 1

Martin Honnen
Martin Honnen

Reputation: 167716

I think you simply need to ensure that any xsl:variable element that has a select attribute has no content so make sure you either have e.g. <xsl:variable name="var-name" select="2"/> or <xsl:variable name="var-name" select="2"></xsl:variable>. So with your C++ you probably want e.g. ss << "<xsl:variable name=\"myplaylist\" select=\"'"<< playlistID <<"'\"/>" ; though I am not really trained to read and write C++.

I also wonder why with your XSLT/XPath you are trying to quote the integer values as that way you get strings in XPath while XPath also has numbers. So depending on your needs you might want to drop the single quotes: ss << "<xsl:variable name=\"myplaylist\" select=\""<< playlistID <<"\"/>" ;.

Upvotes: 1

Related Questions