0

I am having the following XSLT, while transforming a XML using this XSLT throws the following error

<xsl:stylesheet>    
    <xsl:output method="xml" indent="yes" />

    <xsl:key name="k1" match="*" use="."/>
    <!-- <xsl:param name="string-value" select="'STRING_TO_FIND'"/> -->

    <xsl:template match="*">
        <rss>
            <xsl:copy-of select="key('k1', 'STRING_TO_FIND')"/>
        </rss>
    </xsl:template>
</xsl:stylesheet>

ERROR

ERROR:  'Could not compile stylesheet'
FATAL ERROR:  'The string "--" is not permitted within comments.'
           :The string "--" is not permitted within comments.

I replaced the following string in place of 'STRING_TO_FIND' in XSLT. This string can be generated dynamically. The sample string which throws the above error is as follows.

                                    <description><![CDATA[                                          <p>LANSING, MI -- An unusual photo and an "off-the-cuff remark" in the Michigan House on Thursday sparked a war of words about the "war on women" that stretched far beyond the walls of the state Capitol.</p> <p>Republican state Reps. Roger Victory of Hudsonville, Pete Pettalia of Presque Isle and Ben Glardon of Owosso were photographed on the House floor holding a series of womens' fashion magazines.</p> <p>"Don't say we don't understand women," Petallia joked, according to a&nbsp;Michigan Public Radio Network&nbsp;reporter, whose tweet quickly spread online and prompted widespread criticism from Democrats.</p> <center> <blockquote class="twitter-tweet" lang="en"> <p><a href="https://twitter.com/MIHouseGOP">@MIHouseGOP</a> members Victory, Pettalia, and Glardon: "Don't say we don't understand women." <a href="https://twitter.com/search?q=%23mileg&amp;src=hash">#mileg</a> <a href="http://t.co/zsifsqrZ1N">pic.twitter.com/zsifsqrZ1N</a></p> &#8212; Jake Neher (@GJNeher) <a href="https://twitter.com/GJNeher/statuses/474599923149578240">June 5, 2014</a></blockquote> <script src="http://platform.twitter.com/widgets.js" async="" charset="utf-8"></script> </center> <p>Petallia later explained his comment -- and provided&nbsp;context -- in a statement.</p> <p>"During a short break on the House floor, Republican Rep. Gail Haines, a leading advocate on women's issues in the Legislature, gave some of us magazines to read and asked to take our photo with them," Petallia said.</p> <p>"A member of the media then walked up behind her and snapped another photo. As part of that lighthearted moment, I made an off-the-cuff remark that has since been taken way out of context."</p> <p>House Democrats responded with a clever&nbsp;tweet of their own.</p> <center> <blockquote class="twitter-tweet" lang="en"> <p>Real Women read bills not fashion mags... <a href="https://twitter.com/GJNeher">@GJNeher</a> <a href="https://twitter.com/RashidaTlaib">@RashidaTlaib</a> <a href="https://twitter.com/RepVickiBarnett">@RepVickiBarnett</a> <a href="https://twitter.com/MIHouseGOP">@MIHouseGOP</a> <a href="https://twitter.com/search?q=%23mileg&amp;src=hash">#mileg</a> <a href="http://t.co/9Tq9fBLm1a">pic.twitter.com/9Tq9fBLm1a</a></p> &#8212; MI House Democrats (@MIHouseDems) <a href="https://twitter.com/MIHouseDems/statuses/474627414514221056">June 5, 2014</a></blockquote> </center> <script src="http://platform.twitter.com/widgets.js" async="" charset="utf-8"></script> <p>It didn't take long for Democrats around the state to weigh in.</p> <p>"The war on women is alive and well in Michigan," said Ingham County Clerk Barb Byrum, a former state representative who was temporarily barred from speaking on the floor two years ago during a debate on a controversial abortion-related bill.</p> <p>"Now three Republican lawmakers today &#8211; all white men &#8211; made an open mockery of women on the House floor by posing with fashion magazines to showcase, in their words, that they understand women's issues."</p> <p>Michigan Democratic Party Chairman Lon Johnson suggested that the Republican lawmakers had turned the "House floor into a frat party" and said they should apologize for their "out of touch Republican agenda."</p> <p>Republican state Rep. Andrea LaFontaine&nbsp;of&nbsp;Columbus Township said she felt that Democrats were blowing the matter out of proportion.</p> <p>"At the end of the Day, I'm so tired of Democrats making victims out of women," she told MLive. "As a successful Republican myself, a young professional who's part of the leadership team in Lansing, this just floors me.</p> <p>"I'm sorry if I seem fired up about it, but at the end of the day, I think I'm going to succeed in my career because of my beliefs, because of my hard work and because of the results that we as Republicans are producing in the state of Michigan."</p> <p><em>Jonathan Oosting is a Capitol reporter for MLive Media Group. <a href="mailto:[email protected]">Email him</a>, find him on <a href="https://www.facebook.com/jonathan.oosting">Facebook</a> or follow him on <a href="http://twitter.com/jonathanoosting">Twitter</a></em></p>                             <script id="advancenews_mobile_app" type="text/javascript" >                                                                                                            m_blog_type = "text";                   m_blog_id = "8002007";                  m_blog_name = "Lansing News";                   m_blog_url = "http://www.mlive.com/lansing-news/index.ssf/";                    m_blog_newspaper = "";                                                                                                          m_entry_title = "Michigan lawmaker\'s joke leads to war of words over \'war on women\'";                                m_entry_categories = "";                                m_entry_author_name = "Jonathan Oosting | [email protected]";                          m_entry_author_username = "joosting";                           m_entry_author_public_email = "Unknown";                                                m_entry_basename = "michigan_lawmakers_joke_leads";                     m_entry_link = "http://www.mlive.com/lansing-news/index.ssf/2014/06/michigan_lawmakers_joke_leads.html";  

How to get rid of this error?

3
  • Did you "escape" the string before using it to replace STRING_TO_FIND? Commented Jun 10, 2014 at 11:13
  • How to escape the string? Can you provide any sample. I didn't do any string escape. Commented Jun 10, 2014 at 11:14
  • 1
    You need to replace ' with \' and " with \". If you don't escape the string, problem happens. For example, if the STRING_TO_FIND is "', 'abc" (without double quotes), your xls:copy-of becomes "key('k1', '', 'abc')" (without double quotes). Commented Jun 10, 2014 at 11:19

1 Answer 1

1

You have a comment of the form <!-- <xsl:param name="string-value" select="'STRING_TO_FIND'"/> --> in the stylesheet which is a syntactically correct comment. However if you have <!-- <xsl:param name="string-value" select="'--'"/> -->, you have a syntax error, see http://www.w3.org/TR/xml/#sec-comments which says

For compatibility, the string " -- " (double-hyphen) MUST NOT occur within comments.

I am not sure why you commented out the xsl:param but then try to manipulate it, the easiest would be to drop the xsl:param instead of commenting it out.

If this question is a follow-up to How to get XML element based on given value then it looks however as you want to find elements with complex content which is not going to work with the suggestion I made in my answer there.

Sign up to request clarification or add additional context in comments.

2 Comments

Is there any way to achieve this?
Keys in XSLT 1.0 work with string values, in XSLT 2.0 they work with primitive values (like strings, the various number types, date, dateTime). They don't help if you want to find an element based on its child or more general descendant elements. Of course you can write XPath expressions to select elements based on descendant elements or you can write XSLT match patterns with such expressions. However if you want to construct the XPath expression at run-time then you would need XSLT 3.0 or an extension function in earlier XSLT versions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.