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

RE: Replacing <break> tag when not followed by line fe

Subject: RE: Replacing <break> tag when not followed by line feed character
From: Cams Ismael <Ismael.Cams@xxxxxxxxxxxxxxx>
Date: Thu, 5 Dec 2002 11:36:19 +0100
xml break tag
Hello Jarno,

this works. Thanks !

Regards,
Ismaël

-----Original Message-----
From: Jarno.Elovirta@xxxxxxxxx [mailto:Jarno.Elovirta@xxxxxxxxx]
Sent: donderdag 5 december 2002 11:21
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE:  Replacing <break> tag when not followed by line feed
character


Hi,

> I have following xml file
> 	<root>
> 		<long>This is a very <break/>
> 		very long text. 
> 		</long>
> 	<root>
> 
> What I want to do is replace every </break> tag and linefeed 
> by \n\, except
> when the </break> tag is followed by  a linefeed (as in the 
> example). Than I
> only want one \n\ instead of 2. What I have no is a replace 
> function for the
> linefeeds and a template match for the break tags. What I 
> like to do is in
> the template match defining when this node is is followed by 
> a linefeed it
> shouldn't be replaced by \n\. Is this somehow possible ?

<xsl:template match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="long">
  <xsl:apply-templates select="node()" mode="replace" />
</xsl:template>

<xsl:template match="break" mode="replace">
  <xsl:if test="not(following::node()[1][self::text() and starts-with(.,
'&#xA;')])">\n\</xsl:if>
</xsl:template>

<xsl:template match="text()" name="replace" mode="replace">
  <xsl:param name="text" select="." />
  <xsl:choose>
    <xsl:when test="contains($text, '&#xA;')">
      <xsl:value-of select="substring-before($text, '&#xA;')" />
      <xsl:text>\n\</xsl:text>
      <xsl:call-template name="replace">
        <xsl:with-param name="text" select="substring-after($text, '&#xA;')"
/>
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$text" />
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

Or something in those lines,

--

Jarno - Grendel: Human Saviour

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

 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.