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

Re: how search end of line in XSL

Subject: Re: how search end of line in XSL
From: Florent Georges <darkman_spam@xxxxxxxx>
Date: Tue, 12 Dec 2006 17:13:09 +0100 (CET)
xslt end of line
Bkesh wrote:

  Hi

> <literallayout>
> This is <b>text</b> 1.
> This is text<sup>2</sup>.
> </literallayout>

> after transformation

> <para>This is text 1.</para>
> <para>This is text2.</par>

  Sorry for responding now, but I wasn't really able to follow XSL List
until today.  So what you want is grouping.  The key is
text()[contains(., '&_#10;')].  Nodes are copied, but the key that is
cut on the new line char.  I assume there is maximum one new line char
in a text node.

  You have to check if the first node in each group is a text node that
contains a new line: in the first group, it can be something else.  You
have also, in all but the last group, to use the substring before the
new line in the next text node.

  You can also check if you are in a group where the only node is a
text node containing a new line, but nothing after the new line, to
prevent generating empty para elements.  You can use normalize-space()
also here.

(drkm)[21] ~/xslt/tests$ cat byomkesh.xsl
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="2.0">

  <xsl:output omit-xml-declaration="yes" indent="yes"/>

  <xsl:template match="literallayout">
    <xsl:copy>
      <xsl:for-each-group
          group-starting-with="text()[contains(., '&#10;')]"
          select="node()">
        <xsl:if test="not(count(current-group()) eq 1
                            and self::text()[contains(., '&#10;')]
                            and substring-after(., '&#10;') eq '')">
          <para>
            <xsl:choose>
              <xsl:when test="self::text()[contains(., '&#10;')]">
                <xsl:value-of select="substring-after(., '&#10;')"/>
              </xsl:when>
              <xsl:otherwise>
                <xsl:copy-of select="."/>
              </xsl:otherwise>
            </xsl:choose>
            <xsl:copy-of select="current-group()[position() gt 1]"/>
            <xsl:variable name="next" select="
                current-group()[last()]
                  / following-sibling::node()[1][self::text()]"/>
            <xsl:if test="contains($next, '&#10;')">
              <xsl:value-of select="substring-before($next, '&#10;')"/>
            </xsl:if>
          </para>
        </xsl:if>
      </xsl:for-each-group>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>

(drkm)[22] ~/xslt/tests$ cat byomkesh.xml
<literallayout>
  This is <b>text</b> 1.
  This is text<sup>2</sup>.
</literallayout>

(drkm)[23] ~/xslt/tests$ saxon byomkesh.xml byomkesh.xsl
<literallayout>
   <para>  This is <b>text</b> 1.</para>
   <para>  This is text<sup>2</sup>.</para>
</literallayout>

(drkm)[24] ~/xslt/tests$

  Regards,

--drkm
























	

	
		
___________________________________________________________________________ 
Dicouvrez une nouvelle fagon d'obtenir des riponses ` toutes vos questions ! 
Profitez des connaissances, des opinions et des expiriences des internautes sur Yahoo! Questions/Riponses 
http://fr.answers.yahoo.com

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.