I cannot develop this logic, can someone help me with this?
I have a lot of logic to make me stuck.
I have XML that is fully dynamic, that is, its Detail node can grow and shrink. Nodes of additional nodes of nodes can also increase and decrease.
<?xml version="1.0" encoding="utf-8" ?> <body> <detail> <FirstName>t1 </FirstName> <LastName>t2</LastName> <Company>t3</Company> <Country>t4</Country> <Proviance>MP</Proviance> </detail> <detail> <FirstName>t5 </FirstName> <LastName>t6</LastName> <Company>t7</Company> <Country>t8</Country> <Proviance>t9</Proviance> </detail> <detail> <FirstName>t10 </FirstName> <LastName>t11</LastName> <Company>t12</Company> <Country>t13</Country> <Proviance>t14</Proviance> </detail> </body>
I am reading XML as follows:
xmlhttp = new XMLHttpRequest(); xmlhttp.open("GET", "/TinyEditor/PreviewBody.xml", true); xmlhttp.send(); xmlDoc = xmlhttp.responseXML;
Now
Every time I read HTML content from the DOM, this happens every time:
var x = tinyMCEPopup.editor.getContent().toString(); alert(x); the x gets the value like this (x can be different at different times) <p>Headline Dear <br /> <br /> <img src="Images/Untitled.png" alt="" /> <br /> <br />Dear <strong>FirstName <strong> LastName</strong></strong></p> <p><strong><br /></strong></p> <p> I am from company <strong> Company</strong> that is located in <strong> Country</strong>, <strong> Proviance</strong>, <strong> City.</strong></p> <p><strong><br /></strong></p> <p>Thanks</p> <p><strong>FirstName</strong> <strong> LastName</strong> </p> <p><strong><br /></strong></p> <p> </p> <p> </p>
Now I want to search for each element of the part in XML in this HTML and I want to replace the text in HTML (FirstName, LastName) with the element value in the XML nodes for each Node part.
After that, I rewrote the formatted HTML content in the DOM. This is logic that I cannot develop, can anyone help me with this?
My efforts:
<xsl:for-each select="Home/menu"> <xsl:variable name="i"><xsl:value-of select="1+position()" /></xsl:variable> <script language="javascript"> var id = '<xsl:value-of select="$i"/>'; var firstname = '<xsl:value-of select="firstname"/>'; var lastrname = '<xsl:value-of select="lastrname"/>'; var firstname = '<xsl:value-of select="firstname"/>'; var lastrname = '<xsl:value-of select="lastrname"/>'; var firstname = '<xsl:value-of select="firstname"/>'; var lastrname = '<xsl:value-of select="lastrname"/>'; $('#CurrProg-'+id).html(functionname('FirstName',firstname)); $('#CurrProg-'+id).html(functionname('LastName',firstname)); $('#CurrProg-'+id).html(functionname('tagname',firstname)); $('#CurrProg-'+id).html(functionname('tagname',firstname)); $('#CurrProg-'+id).html(functionname('tagname',firstname)); $('#CurrProg-'+id).html(functionname('tagname',firstname)); </script> </xsl:for-each>
and function
$(document).ready(function () { xmlDoc = $.xsl.load('XML/PreviewBody.xml'); xslHome = $.xsl.load('XSL/Preview.xsl'); $('#Page_Content').getTransform( xslHome, xmlDoc ); });
function textReplace(actualtext, replacementtext) { var actualtext = new RegExp(actualtext, 'ig'); document.getElementById('content').innerHTML = x.replace(actualtext, replacementtext); }
But it does not work for dynamic XML, I need to fix the node in advance ... I want to do this at runtime.