xsl-list
[Top] [All Lists]

RE: Replacing <break> tag when not followed by line feed ch aracter

2002-12-05 03:36:19
Hello Jarno,

this works. Thanks !

Regards,
Ismaël

-----Original Message-----
From: Jarno(_dot_)Elovirta(_at_)nokia(_dot_)com 
[mailto:Jarno(_dot_)Elovirta(_at_)nokia(_dot_)com]
Sent: donderdag 5 december 2002 11:21
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] 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



<Prev in Thread] Current Thread [Next in Thread>
  • RE: Replacing <break> tag when not followed by line feed ch aracter, Cams Ismael <=