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

Re: Passing element nodes through string functions (WAS RE:

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

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.