This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
insert tags out of context in XSL
- From: Peter Carlson <carlson at bookandhammer dot com>
- To: "xsl-list at lists dot mulberrytech dot com" <xsl-list at lists dot mulberrytech dot com>
- Date: Fri, 03 May 2002 08:11:34 -0700
- Subject: [xsl] 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>
The code I am using to convert at the linefeed is (from skew.org)
See notes in ### below for where I want to put </para><para>
<xsl:template name="lf2br">
<!-- import $StringToTransform -->
<xsl:param name="StringToTransform"/>
<xsl:choose>
<!-- string contains linefeed -->
<xsl:when test="contains($StringToTransform,'
')">
<!-- output substring that comes before the first linefeed
-->
<!-- note: use of substring-before() function means
-->
<!-- $StringToTransform will be treated as a string,
-->
<!-- even if it is a node-set or result tree fragment.
-->
<!-- So hopefully $StringToTransform is really a string!
-->
<xsl:value-of
select="substring-before($StringToTransform,'
')"/>
<!-- by putting a 'br' element in the result tree instead
-->
<!-- of the linefeed character, a <br> will be output at
-->
<!-- that point in the HTML
-->
<!-- #######THIS IS WHERE I WANT TO PUT </para><para> ########-->
<br/>
<!-- repeat for the remainder of the original string -->
<xsl:call-template name="lf2br">
<xsl:with-param name="StringToTransform">
<xsl:value-of
select="substring-after($StringToTransform,'
')"/>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<!-- string does not contain newline, so just output it -->
<xsl:otherwise>
<xsl:value-of select="$StringToTransform"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list