Re: [xsl] manipulating text and not losing elements

Subject: Re: [xsl] manipulating text and not losing elements
From: Jon Gorman <jonathan.gorman@xxxxxxxxx>
Date: Thu, 13 Oct 2005 09:57:11 -0500
> <xml version="1.0">
> <document>
> <sender>someone@xxxxxxxxxxx</sender>
> <indent1>1245 This is some indented text with <italic>Italic</italic>
> and <bold>bold</bold> text</indent1>
> <paragraph>1246 Italic and bold tags are not limited  they can
> <italic>appear</italic> anywhere within the document</paragraph>
> </document>

...

the
> only way to accomplish this is with substring, but using a substring
> requires outputting using <xsl:value-of> which negates all following
> children.

It's probably not the only way, but I think you might have a bad
mental model going on here.  Think of text nodes as always being leaf
children.

ie
> <xml version="1.0">
> <document>
> <sender>someone@xxxxxxxxxxx</sender>
> <indent1>1245 This is some indented text with <italic>Italic</italic>
> and <bold>bold</bold> text</indent1>
> <paragraph>1246 Italic and bold tags are not limited  they can
> <italic>appear</italic> anywhere within the document</paragraph>
> </document>

- = layer in the tree, so nodes mentioned are "contained" by node with
one less -

document
-sender
--text node value=someone@xxxxxxxxxxx
-indent1
--text node value=1245 This is some indented text with
--italic
---text node value=Italic
--text node value= and
--bold
--- text

and so on.

The trick here is that I'm not sure entirely when those number appear.
 If it's regular enough, say always at the start of the first text
node of a paragraph or an indent and is always four lines just do
something like (not tested)

<xsl:value-of (substring(text()[1],4) />
<xsl:apply-templates select="node()[position() > 1]" />

So you process the first text node and then can resume recursing down the
tree.

You might need to get more complicated if you're going to stick to 1.0
and don't know when the numeric sequences can appear.


Jon Gorman






Ultimately I would like the line tagged as <indent1> to
> read the following:
>
> <p classs="indent1">This is some indented text with <em>Italic</em>
> and <strong>bold</strong> text</p>
>
> Ok, hopefully that illustrates my problem well. Thanks in advance for
> any help you guys can offer.
>
> Cheers,
>
> Spencer

Current Thread