Can someone help me with some logic?

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&nbsp; <strong> LastName</strong></strong></p> <p><strong><br /></strong></p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I am from company <strong> Company</strong> that is located in <strong> Country</strong>,&nbsp; <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>&nbsp;</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </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 () { /* load all xsl and xml file */ 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.

+4
source share
2 answers

I would prefer to use jQuery for this purpose. It is quite convenient for such tasks, and you do not need to create your own code for each browser.

http://www.vagrantradio.com/2009/10/how-to-parse-xml-using-jquery-and-ajax.html

+4
source

you should use xslt to generate your content, not a script

If you still want to do whart, you can reconfigure forllowing: use {FirstName} instead of FirstName , as you can find it better (fo fo FirstName that cannot be replaced) and btw drop xslt and run the xml loop with dom

Also, I don't think you are using the new RegExp() right check guides

btw you say that for any elelemnt element but not posseble, you must select 1 part element and a loop through your siblings

this is a good code replacement in js (don't know about jquery (sorry))

 function textReplace(actualtext, replacementtext) { document.getElementById('content').innerHTML = document.getElementById('content').innerHTML.replace(actualtext,replacementtext); } 
0
source

Source: https://habr.com/ru/post/1379777/


All Articles