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

RE: Confision with replace-string template and attribu

Subject: RE: Confision with replace-string template and attributes
From: "Hattersley, John" <jhattersley@xxxxxxx>
Date: Thu, 11 Mar 2004 05:44:46 -0500
xsl replace string
>> I would guess that you are trying to add the attribute after you have already >> added other child nodes.

Thanks for the response Josh, I didn't realise that was the case, I was adding child elements to aid debugging! Don't I feel the fool.

For anyone else who has this problem, xalan-j didn't produce any error messages.

Cheers,
John



-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Josh Canfield
Sent: 10 March 2004 20:11
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE:  Confision with replace-string template and attributes


Josh

-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Hattersley,
John
Sent: Wednesday, March 10, 2004 10:48 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  Confision with replace-string template and attributes


Hi all,

Wondering if somebody could shed some light on this one, I'm using the ubiquitous replace-string template, e.g

 <xsl:template name="replace-string">
    <xsl:param name="text"/>
    <xsl:param name="from"/>
    <xsl:param name="to"/>
    <xsl:choose>
      <xsl:when test="contains($text, $from)">
	<xsl:variable name="before" select="substring-before($text, $from)"/>
	<xsl:variable name="after" select="substring-after($text, $from)"/>
	<xsl:variable name="prefix" select="concat($before, $to)"/>

	<xsl:value-of select="$before"/>
	<xsl:value-of select="$to"/>
        <xsl:call-template name="replace-string">
	  <xsl:with-param name="text" select="$after"/>
	  <xsl:with-param name="from" select="$from"/>
	  <xsl:with-param name="to" select="$to"/>
	</xsl:call-template>
      </xsl:when> 
      <xsl:otherwise>
        <xsl:value-of select="$text"/>  
      </xsl:otherwise>
    </xsl:choose>            
 </xsl:template>

I'm trying to use this to replace the value of an attribute, e.g.

            <xsl:variable name="newValue">
               <xsl:call-template name="replace-string">
	               <xsl:with-param name="text" select="$attrib"/>
	      	       <xsl:with-param name="from" select="$toReplace"/>
	      	       <xsl:with-param name="to" select="$replaceWith"/>
               </xsl:call-template>
            </xsl:variable>
            <xsl:attribute name="value"><xsl:value-of select="$newValue"/></xsl:attribute>

If I do this an attribute called value is not added to my element.  However, if I change the final line to:

            <xsl:element name="value"><xsl:value-of select="$newValue"/></xsl:element>

A child element called value is successfully added.
I'm using xalan-j.
Any help would be much appreciated.
Cheers, 
John



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


 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.