[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: Passing element nodes through string functions (WAS RE: [xsl] Preserving inline elements when using string functions)


Subject: Re: Passing element nodes through string functions (WAS RE: [xsl] Preserving inline elements when using string functions)
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 28 Aug 2003 17:27:08 +0100

div.xml

<page>
    <bodytext>This is the <link url="zzz">link</link> xxx
    This is another line
    and a <link url="zzz">link2</link> 2nd
    and a third</bodytext>
</page>


div.xsl

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                 version="1.0">

<xsl:output indent="no"/>

<xsl:key name="x" match="bodytext/node()"
use="generate-id((..|preceding-sibling::text()[contains(.,'&#10;')][1])[last()])"/>

<xsl:template match="page">
<html>
<head>
<title>testing...</title>
</head>
<xsl:apply-templates/>
</html>
</xsl:template>

<xsl:template match="link">
<a href="{@url}">
<xsl:apply-templates/>
</a>
</xsl:template>


<xsl:template match="bodytext">
<body>
<xsl:for-each select=".|text()[contains(.,'&#10;')]">
 <xsl:call-template name="d1">
 <xsl:with-param name="s" select="substring-after(self::text(),'&#10;')"/>
 </xsl:call-template>
</xsl:for-each>
</body>
</xsl:template>

<xsl:template name="d1">
 <xsl:param name="s"/>
  <xsl:text>&#10;</xsl:text>
<xsl:choose>
 <xsl:when test="contains($s,'&#10;')">
  <div><xsl:value-of select="substring-before($s,'&#10;')"/></div>
 <xsl:call-template name="d1">
 <xsl:with-param name="s" select="substring-after($s,'&#10;')"/>
 </xsl:call-template>
 </xsl:when>
 <xsl:otherwise>
  <div>
  <xsl:value-of select="$s"/>
  <xsl:apply-templates
select="key('x',generate-id(.))[position()&lt;last()]"/>
<xsl:value-of
select="substring-before(key('x',generate-id(.))[last()],'&#10;')"/>
  </div>
 </xsl:otherwise>
 </xsl:choose>
</xsl:template>


</xsl:stylesheet>



$ saxon div.xml div.xsl
<html><head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
   <title>testing...</title></head>
    <body>
<div>This is the <a href="zzz">link</a> xxx</div>
<div>    This is another line</div>
<div>    and a <a href="zzz">link2</a> 2nd</div>
<div>    and a third</div></body>
</html>



David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

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



Current Thread