gpt4 book ai didi

java - 使用 XSLT 转换 XML 时如何防止 fatal error

转载 作者:行者123 更新时间:2023-12-01 12:52:09 26 4
gpt4 key购买 nike

我有以下 XSLT,使用此 XSLT 转换 XML 时会引发以下错误

<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:  'Could not compile stylesheet'
FATAL ERROR: 'The string "--" is not permitted within comments.'
:The string "--" is not permitted within comments.

我在 XSLT 中替换了以下字符串来代替“STRING_TO_FIND”。该字符串可以动态生成。抛出上述错误的示例字符串如下。

                                    <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:joosting@mlive.com">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 | joosting@mlive.com";                          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";  

如何消除这个错误?

最佳答案

您有一条格式为 <!-- <xsl:param name="string-value" select="'STRING_TO_FIND'"/> --> 的评论在样式表中,这是语法正确的注释。但是,如果您有 <!-- <xsl:param name="string-value" select="'--'"/> --> ,您有语法错误,请参阅 http://www.w3.org/TR/xml/#sec-comments其中说

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

我不知道你为什么注释掉 xsl:param但然后尝试操纵它,最简单的方法是删除 xsl:param而不是将其注释掉。

如果这个问题是 How to get XML element based on given value 的后续问题但是,看起来您想要查找具有复杂内容的元素,这与我在答案中提出的建议不符。

关于java - 使用 XSLT 转换 XML 时如何防止 fatal error ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24139469/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com