Re: [xslt] Parsing and marking up text into xml with libxslt



Sam Liddicott schrieb:
I need to do some limited text-node parsing in libxslt.

I find parsing text very difficult in libxslt [...]

[...] libxslt doesn't seem to have regexp support, or at least not
widely distributed or even packaged for most platforms (including mine).

str::tokenize etc are not good because they are too destructive and
destroy the separating tokens.

The simplest expression [...] one character at a time.

Clearly that is nuts.

I'll probably have to go for use of: contains, substring-before,
substring-after, substring and string-length; and maybe str:tokenize
just to get lengths of substrings up to multiple delimeters.

Clearly that is nuts too.

Have I missed anything obvious?

As you mention Perl, you may find it beneficial to use Perl for string
manipulation from within XSLT, Perl being far superior to XSLT 1.0 in
this respect.

    sub ts_to_w3cdtf { ... }

    XML::LibXSLT->register_function(
      'urn:perl', 'ts-to-w3cdtf', \&ts_to_w3cdtf);

    <xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
      xmlns:perl="urn:perl">

      <xsl:value-of select="perl:ts-to-w3cdtf( @timestamp )"/>

Michael Ludwig


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]