This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

insert tags out of context in XSL


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 &lt;para&gt;, 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,'&#xA;')">
                <!-- 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,'&#xA;')"/>
                <!-- 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,'&#xA;')"/>
                    </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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]