[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

How to use parse-xml-fragment with a string that conta

Subject: How to use parse-xml-fragment with a string that contains a less-than symbol (and the less-than symbol is not part of a start- or end-tag)?
From: "Roger L Costello costello@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 22 Feb 2021 17:30:46 -0000
 How to use parse-xml-fragment with a string that conta
Hi Folks,

I want to parse, as XML, the contents of this comment:

<!--abc<style>hello, world</style>def-->

The contents of that comment is not well-formed XML, so I extracted the
contents and placed a <wrapper> element around it:

<xsl:variable name="wrapped-comment" as="xs:string">
    <xsl:value-of select="concat('&lt;wrapper&gt;', comment()/data(),
'&lt;/wrapper&gt;')"/>
</xsl:variable>

Then I applied parse-xml-fragment to the variable:

<xsl:sequence select="parse-xml-fragment($wrapped-comment)" />

That produced the desired result:

<wrapper>abc<style>hello, world</style>def</wrapper>

Yea!

Pretty cool. (Thanks Martin)

However, the actual comment that I have contains some nastiness: after the
<style> end-tag is this string: <![endif]

So, the actual comment is this:

<!--abc<style>hello, world</style><![endif]-->

Eek!

When I apply parse-xml-fragment (after wrapping the comment's content in a
<wrapper> element) I get this error:

   First argument to parse-xml-fragment() is not a well-formed
   and namespace-well-formed XML fragment.

That makes perfect sense since the unescaped '<' at the end of the comment is
causing problems.

Is there an elegant, simple solution to this problem, without manually
changing <![endif] to &lt;![endif]?

/Roger

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.