xsl-list
[Top] [All Lists]

Re: [xsl] problem with transforming mixed content

2020-08-14 21:34:20
On Sat, Aug 15, 2020 at 02:16:04AM -0000, Wolfhart Totschnig 
wolfhart(_dot_)totschnig(_at_)mail(_dot_)udp(_dot_)cl scripsit:
<title>THE TITLE OF THE BOOK WITH SOME <i>ITALICS</i> AND SOME MORE WORDS:
THE SUBTITLE OF THE BOOK WITH SOME <i>ITALICS</i></title>

What I would like to do is
1) separate the title from the subtitle (i.e., divide the data at the colon)
and put each in a separate element node;
2) all the while maintaining the <i> markup;
3) and perform certain string manipulations on all of the text nodes; for
the purposes of this post, I will use the example of converting upper-case
to lower-case.

So the desired output is the following:

<title>the title of the book with some <i>italics</i> and some more
words</title>
<subtitle>the subtitle of the book with some <i>italics</i></subtitle>

<xsl:template match="title">
    <title>
      <xsl:sequence select="serialize(node()) => substring-before(':') => 
lower-case() => parse-xml-fragment()" />
    </title>
    <subtitle>
      <xsl:sequence select="serialize(node()) => substring-after(':') => 
lower-case() => parse-xml-fragment()" />
    </subtitle>
  </xsl:template>

gives

<title>the title of the book with some <i>italics</i> and some more 
words</title>
<subtitle> the subtitle of the book with some <i>italics</i></subtitle>

That's XSLT 3.0, it assumes there's always a colon, and could be made
rather more robust, but that's the general idea; treat the contents of
the element as a string sometimes and as nodes sometimes.

-- 
Graydon Saunders  | graydonish(_at_)gmail(_dot_)com
Þæs oferéode, ðisses swá mæg.
-- Deor  ("That passed, so may this.")
--~----------------------------------------------------------------
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>