Re: [xsl] String Replacement in XML using XSLT

Subject: Re: [xsl] String Replacement in XML using XSLT
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Mon, 25 Sep 2006 11:22:04 -0700
I would prefer this to be really an xml/xslt problem and solution.

For this purpose, I'd rather have :

<content name="subject"> Hello <BUYERS_NAME/></content>

instead of:

<content name="subject"> Hello [[BUYERS_NAME]]</content>

and the same for any other replacement targets.


Then I'd provide the replacement text simply in the template matching
the target:

<xsl:template match="BUYERS_NAME">
 <xsl:value-of select="/*/BUYERS_NAME">
</xsl:template>

Or I could make all replacements using a single template only:

<content name="subject"> Hello <insert>BUYERS_NAME</insert></content>

<xsl:template match="insert">
 <xsl:value-of select="/*/*[name() = current()]">
</xsl:template>


-- Cheers, Dimitre Novatchev --------------------------------------- Truly great madness cannot be achieved without significant intelligence. --------------------------------------- To invent, you need a good imagination and a pile of junk -------------------------------------- You've achieved success in your field when you don't know whether what you're doing is work or play


On 9/25/06, Senthilkumaravelan Krishnanatham <senthil@xxxxxxxxx> wrote:
Hi All,
I need help in logic of  replacing the string in XML for the below
input.
<test>
<content_vars>
<content name="subject"> Hello [[BUYERS_NAME]]</content>
<content name="text">  REF Order [ORDER_NUMBER]</content>
</content_vars>
<BUYERS_NAME>
SENTHIL
</BUYERS_NAME>
< ORDER_NUMBER >
1234
</ORDER_NUMBER >

</test>

Output should be
<html>
<body>
<P>Hello SENTHIL</p>
<p> REF Order 1234</p>
</body>
</html>

Is there anyway I can do it in XSLT?
Any suggestion are welcome.

Thanks,
Senthil

Current Thread