Java 如何在使用XSLT转换XML时防止致命错误

Java 如何在使用XSLT转换XML时防止致命错误,java,xml,xslt,transformation,Java,Xml,Xslt,Transformation,我使用以下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'"/> --> &

我使用以下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>
我将以下字符串替换为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";  
密歇根州兰辛——周四,在密歇根州众议院,一张不同寻常的照片和一句“即兴评论”引发了一场关于“妇女战争”的口水战,这场战争远远超出了州议会大厦的围墙。

共和党州代表。哈德逊维尔的罗杰·维克托、普雷斯克岛的皮特·佩塔里亚和奥沃索的本·格拉登在家里的地板上拿着一系列女性时尚杂志拍照。

“别说我们不了解女性,”据密歇根公共广播网记者说,佩塔利亚开玩笑说,他们的推特很快在网上传播开来,并引起了民主党人的广泛批评。

成员维克多、佩塔利亚和格拉登:“不要说我们不了解女性。”

&8212;杰克·内尔(@GJNeher)佩塔利亚后来在一份声明中解释了他的评论,并提供了背景。

佩塔利亚说:“在众议院短暂休息期间,共和党众议员盖尔·海恩斯(Gail Haines)是立法机构妇女问题的主要倡导者,他给了我们一些杂志阅读,并要求我们与他们合影。”一名媒体成员随后走到她身后,拍下了另一张照片。作为那轻松时刻的一部分,我发表了一句即兴的评论,这句话后来被断章取义了。”

众议院民主党人用自己的一条聪明的推特回应。

真正的女性读的是法案,而不是时尚杂志……

&该州的民主党人没过多久就参与进来了。

英厄姆县的书记官巴布·拜伦(Barb Byrum)说:“在密歇根州,对妇女的战争依然存在,而且进行得很顺利。”他是前州代表,两年前在一场有争议的堕胎相关法案的辩论中被暂时禁止发言今天有三位共和党议员–;全是白人–;密歇根州民主党主席朗·约翰逊建议共和党议员将“众议院变成了兄弟会”,并表示他们应该为自己的行为道歉与共和党议程脱节。”

来自哥伦布镇的共和党州众议员安德里亚·拉方丹(Andrea LaFontaine)说,她觉得民主党人把这件事搞得不成比例。

她告诉姆利夫:“归根结底,我已经厌倦了民主党人把女性当作受害者。”,作为兰辛市领导团队的一员,我对这件事感到非常失望。

“如果我对此感到愤怒,我很抱歉,但归根结底,我认为我会在我的职业生涯中取得成功,因为我的信念,因为我的辛勤工作,也因为我们共和党人在密歇根州取得的成果。”乔纳森·奥斯汀是姆利夫传媒集团的国会记者,在博客上找到他或跟踪他

m_blog_type=“text”;m_blog_id=“8002007”;m_blog_name=“兰新新闻”;m_blog_url=”http://www.mlive.com/lansing-news/index.ssf/"; m_blog_paper=“”;m_entry_title=“密歇根州立法者的笑话引发了关于“妇女战争”的口水战”;m_entry_categories=“”;m_entry_author_name=“Jonathan Oosting|joosting@mlive.com"; m_entry_author_username=“joosting”;m_entry_author_public_email=“未知”;m_entry_basename=“密歇根州议员们开玩笑的领导者”;m_条目_链接=”http://www.mlive.com/lansing-news/index.ssf/2014/06/michigan_lawmakers_joke_leads.html";


如何消除此错误?

您在样式表中有一个形式为
的注释,这是一个语法正确的注释。但是,如果您有
,则会出现语法错误,请参见

为了兼容,字符串“-”(双连字符)不能出现 在评论中

我不知道你为什么要注释掉
xsl:param
,但是如果你试图对它进行操作,最简单的方法是删除
xsl:param
,而不是注释掉它


如果这个问题是后续问题,那么它看起来像是您想要查找具有复杂内容的元素,这与我在回答中提出的建议不符。

在使用字符串替换字符串\u to \u find之前,您是否“转义”了该字符串?如何转义该字符串?你能提供样品吗。我没有做任何字符串转义。您需要将“替换为”和“替换为”。如果不转义字符串,问题就会发生。例如,如果字符串_TO_FIND是“,”abc“(不带双引号),那么您的xls:copy就变成了“key('k1','','abc')”(不带双引号)。有什么方法可以实现这一点吗?XSLT 1.0中的键使用字符串值,XSLT 2.0中的键使用基本值(如字符串、各种数字类型、日期、日期时间)。如果您希望基于元素的子元素或更一般的子元素查找元素,则它们没有帮助。当然,您可以编写XPath表达式来基于子元素选择元素,也可以使用此类表达式编写XSLT匹配模式。但是,如果希望在运行时构造XPath表达式,则需要XSLT 3.0或扩展函数
                                    <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";