This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: insert tags out of context in XSL
- From: Dimitre Novatchev <dnovatchev at yahoo dot com>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Fri, 3 May 2002 10:54:20 -0700 (PDT)
- Subject: [xsl] Re: insert tags out of context in XSL
- Reply-to: xsl-list at lists dot mulberrytech dot com
> Hi,
>
> I am trying to break up a single block of text into multiple blocks
> at
> the
> linefeed marker.
>
> I found the l2br solution in the FAQ, but I don't want to put a <br
> />,
> I
> want to use </para><para>.
>
>
> Since these tags are out of context in the xsl, it won't work since
> it's not
> valid XML. I tried using the <para>, but they are considered
> tags
> in
> the next transform.
>
> Any suggestions or pointing to the correct FAQ would be helpful.
>
> Thanks
>
> --Peter
>
> My XML looks like
>
> <root>
> <para>xxx
> yyy
> zzz
> </para>
>
> I want to transform it to
>
> <root>
> <para>xxx</para>
> <para>yyy</para>
> <para>zzz</para>
> </root>
>
No extensions (standard or non-standard) are needed here.
Using FXSL (its functional tokenizer) one will write the following:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:vendor="http://icl.com/saxon"
exclude-result-prefixes="vendor"
>
<xsl:import href="strSplit-to-Words.xsl"/>
<xsl:output indent="yes" omit-xml-declaration="yes"/>
<xsl:template match="/">
<xsl:variable name="vwordNodes">
<xsl:call-template name="str-split-to-words">
<xsl:with-param name="pStr" select="/root/para"/>
<xsl:with-param name="pDelimiters"
select="' '"/>
</xsl:call-template>
</xsl:variable>
<root>
<xsl:apply-templates
select="vendor:node-set($vwordNodes)/*"/>
</root>
</xsl:template>
<xsl:template match="word">
<xsl:if test="string(.)">
<para>
<xsl:value-of select="."/>
</para>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
This transformation, when applied to your source xml:
<root>
<para>xxx
yyy
zzz
</para>
</root>
will produce the following result:
<root>
<para>xxx</para>
<para>yyy</para>
<para>zzz</para>
</root>
Hope this helped.
Cheers,
Dimitre Novatchev.
__________________________________________________
Do You Yahoo!?
Yahoo! Health - your guide to health and wellness
http://health.yahoo.com
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list