[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: String Replacement in XML using XSLT
Dimitre Novatchev wrote:
Or I could make all replacements using a single template only: Nice thinking, I should use that myself (I tend to invent new tags and constructs every now and then, like {{REPLACEME}} :D ). Though I wonder if Senthil really has the choice of changing his input data. Of course, only Senthil could answer that Q. In addition, you (Senthil) may use the best of breed, if you can use XSLT 2, or XSLT 1 with node-set extension (not tested): <xsl:variable name="content-tree"> <xsl:for-each select="//content"> <xsl:copy> <xsl:for-each select="tokenize(., '\[|\]')"> <xsl:if test="position() mod 2"> <text><xsl:value-of select="." /></text> </xsl:if> <xsl:if test="not(position() mod 2)"> <insert><xsl:value-of select="." /></insert> </xsl:if> </xsl:for-each> </xsl:copy> </xsl:for-each> </xsl:variable> This will give you a tree that looks something like this (if more [bla] pairs are inside a string, it goes well as well, I think): <content name="subject"> <text>Hello </text> <insert>BUYERS_NAME</insert> </content> <content name="text"> <text>REF Order </text> <insert>ORDER_NUMBER</insert> </content> This variable $content-tree can now be used anywhere with the template from Dimitre. I use similar techniques to tokenize CSV or likewise delimited input. For XSLT-1 remember to use the exslt:node-set extension Cheers, Abel Braaksma http://abelleba.metacarpus.com
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|