Subject: Re: [xsl] XML text search & replace From: Martin Honnen <Martin.Honnen@xxxxxx> Date: Wed, 23 Mar 2011 15:10:19 +0100 |
Hello
There is a requirement to search for a particular pattern in XML documents and replace them by reading another XML file and copying over the replacement text correcpinding to the original text. I have been trying to use<xsl:analyze-string> in xslt 2.0. but I am not sure how to read another XML file using this tag.
As an example, if I have some text tagged within<para> tags :
<para> this is a simple text</para>
I have an external xml file of the form:
<matchtext>simple</matchtext> <replacetext>hard</replacetext>
In my<xsl:matching-substring>, can I use doc() to read the external XML file and replace the text?
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsd="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xsd" version="2.0">
<xsl:template match="para"> <xsl:copy> <xsl:apply-templates/> </xsl:copy> </xsl:template>
<xsl:template match="para//text()"> <xsl:analyze-string select="." regex="{$rep-pattern}"> <xsl:matching-substring> <xsl:value-of select="key('rep-key', ., $rep-doc)/replacetext"/> </xsl:matching-substring> <xsl:non-matching-substring> <xsl:value-of select="."/> </xsl:non-matching-substring> </xsl:analyze-string> </xsl:template>
<replacements> <replacement> <matchtext>simple</matchtext> <replacetext>hard</replacetext> </replacement> </replacements>
Martin Honnen http://msmvps.com/blogs/martin_honnen/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] XML text search & replace, Liam R E Quin | Thread | [xsl] Q: Kaysian set difference in , Hermann Stamm-Wilbra |
Re: [xsl] XML text search & replace, Liam R E Quin | Date | Re: [xsl] Balisage and XML Prague c, Abel Braaksma |
Month |