xsl-list
[Top] [All Lists]

Re: Fwd: Parsing Entities

2006-01-10 06:00:06

  I've looked at saxon:parse
  (http://www.saxonica.com/documentation/extensions/functions/parse.html)
  though that seems specific to CDATA and expects a single root node XML
  document.


Not sure what you mean by "specific to CDATA". XSL doesn't have anything
of type CDATA, and saxon:parse() just requires a string which you can
easily extract out of your text node. You need to make sure it's well
formed XML so has a single top level element (note this is not the root
node, it is the _child_ of the root node), so you can concatenate the
element content with a start and end tag, parse, then extract the
contents of the element:

saxon:parse(concat('<x>',letter_text,'</x>'))/x/node()

though I'm aware that XSLT isn't really
very good for text processing.

XSL2 is a lot better than XSLT1 (for instance it would be fairly easy to
parse that amount of escaped xml, just using xsl without any extensions.
for example:


parse.xml

<letter_text>&lt;p&gt;Some random letter text :(.&lt;/p&gt;&lt;p&gt;Will
this work?&lt;/p&gt;</letter_text>


parse.xsl

 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
   xmlns:d="data:,dpc"
 version="2.0">
<xsl:import href="http://www.dcarlisle.demon.co.uk/htmlparse.xsl"/>

<xsl:output method="xml"/>

<xsl:template match="letter_text">
<xsl:copy-of select="d:htmlparse(.,'',false())"/>
</xsl:template>

 
</xsl:stylesheet>



$ saxon8 parse.xml parse.xsl
<?xml version="1.0" encoding="UTF-8"?><p>Some random letter text :(.</p><p>Will
this work?</p>




________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>