xsl-list
[Top] [All Lists]

Re: [xsl] Breaking paragraphs one linebreaks

2019-05-09 14:55:40
Am 09.05.2019 um 21:42 schrieb Manuel Souto Pico 
terminolator(_at_)gmail(_dot_)com:


@Martin, your example works really well. I had to edit the expression,
as in my real files sometimes they have used lists instead of linebreaks:

<xsl:param name="lb" as="xs:string">&lt;/?(li|ul|br)\s*/?&gt;</xsl:param>

However, I can see what I would also need to split at the end of
sentences when there's no escaped tag but just final punctuation. To
avoid the transformation eating the punctuation, I have tried with a
lookbehind assertion but it seems it's not supported:

<xsl:param name="lb"
as="xs:string">(?<=[.!?])\s|&lt;/?(li|ul|br)\s*/?&gt;</xsl:param>

Any ideas?


In general, if there is markup, it might be better to try to parse it,
in your initial sample you seemed to have simple HTML empty element
syntax with <br> elements, now with the adapted regular expression it
seems you expect opening and closing tags.

If you know the escaped markup is an XML fragment then I would try to
parse it with the "parse-xml-fragment" function, if it is HTML, then I
would look into using David Carlisle's HTML parser implementation done
in pure XSLT 2 or use an extension function like the commercial editions
of Saxon offer.

After parsing, you can then apply normal templates or grouping constructs.

As for lookbehind assertions in regular expressions, I don't think the
XPath/XSLT/XQuery regular expression syntax supports that. I think Saxon
allows a flag on regular expression constructs to drop down to platform
specific regular expression implementations, that might work if the Java
platform or the .NET platform supports lookbehinds.
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

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