Results 1 to 3 of 3

Thread: XML/XSL: Help with JavaScript please

  1. #1

    Thread Starter
    Addicted Member DJ_Catboy's Avatar
    Join Date
    Jan 2003
    Location
    Suffolk, UK
    Posts
    159

    XML/XSL: Help with JavaScript please

    Hi,

    I have an XML file that I need to translate into a different format. To be clear, I have a field that has carriage returns embedded that is one field - I need to split this into several fields. Example:

    Source
    =====
    <text>
    line 1(invisible CR/LF)
    line 2(invisible CR/LF)
    line 3
    </text>

    Required Target
    ===========
    <text>line1</text>
    <text>line2</text>
    <text>line3</text>

    The only way that I can think to achieve this is to use JavaScript in my XSL transformation. Can anybody supply an example of this or has anybody else come across this problem?

    Would be very grateful for some assistance.

    Thanks in advance,
    DJ

  2. #2
    Lively Member Brandito's Avatar
    Join Date
    Nov 2000
    Location
    Here, There, Every Where!
    Posts
    106

    crap load of code

    There is not allot of examples for coding javascript/xml
    I know this is a lot of code... but here is an example from a site I put together. This may or may not help.

    Code:
    <html>
    <head>
    
    <script language="JavaScript" for="window" event="onload">
    
    /* ----------------------------------------
       Brandon Petty's JavaScript/XML Calander
       Note:  This project is under heavey
              construction!  Coders welcome!
       ---------------------------------------- */
    
    var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
    xmlDoc.async="false"
    xmlDoc.load("Calander.xml")
    var oMonth = xmlDoc.getElementsByTagName("Month")
    
    document.write("<html><head><title>Cerner Explorer Calander</title></head>")
    document.write("<body bgcolor='white'>")
    document.write("<a href='./index.php'><b><< Home</b></a> <br><br>")
    
    for (i=0; i <= oMonth.length - 1; i++)
    {
    	document.write("<hr align='left' width='250px'>Month: " + oMonth(i).getAttribute("Name"))
    
    		for (x=0; x <= oMonth(i).childNodes.length - 1; x++)
    		{
    			document.write("<hr align='left' width='45px'>")
    
    				for (z=0; z <= oMonth(i).childNodes.item(x).childNodes.length - 1; z++)
    				{
    					if (z == 0)
    						document.write("Date: " + oMonth(i).childNodes.item(x).childNodes.item(z).text + " <br> ")
    					else
    						document.write("Description: " + oMonth(i).childNodes.item(x).childNodes.item(z).text + " <br> ")
    				}
    		}
    }
    
    document.write("<hr align='left' width='250px'>")
    document.write("</body></html>")
    
    </script>
    
    <title>Explorer Calander</title>
    </head>
    
    <body bgcolor="pink">
      <center>If you are seeing this... contact us or update your browser</center>
    </body>
    </html>
    Here is an example of the XML

    Code:
    <?xml version="1.0" encoding="ISO8859-1" ?> 
    <Calander>
    	<Month Name="January">
    	</Month>
    
    	<Month Name="Febuary">
    	</Month>
    
    	<Month Name="March">
    		<Date>
    			<Day>15</Day>
    			<Content>Krysta's Birthday</Content>
    		</Date>
    	</Month>
    
    	<Month Name="April">
    	</Month>
    
    	<Month Name="May">
    	</Month>
    
    	<Month Name="June">
    	</Month>
    
    	<Month Name="July">
    		<Date>
    			<Day>14</Day>
    			<Content>Brandon's Birthday</Content>
    		</Date>
    	</Month>
    
    	<Month Name="August">
    	</Month>
    
    	<Month Name="September">
    	</Month>
    
    	<Month Name="October">
    	</Month>
    
    	<Month Name="November">
    	</Month>
    
    	<Month Name="December">
    	</Month>
    </Calander>
    again.. this might not help you... but it teaches you the basics for working xml with javascript

    Brandito
    Master of Cyber Fu - A Temple of Digital Chi

  3. #3

    Thread Starter
    Addicted Member DJ_Catboy's Avatar
    Join Date
    Jan 2003
    Location
    Suffolk, UK
    Posts
    159
    Many thanks - I will try some stuff out with that!

    DJ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width