[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: insert tags out of context in XSL

Subject: Re: insert tags out of context in XSL
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Fri, 3 May 2002 10:54:20 -0700 (PDT)
insert tags
> 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>
> 


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="'&#10;&#13;'"/>
        </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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.