xsl-list
[Top] [All Lists]

Re: [xsl] XML to Javascript

2007-01-27 02:59:52
Philip
Sure, you can put in a linefeed for readability but br is a linefeed/break in HTML. In XML just use something like:<text>&-#-x-1-0-;</text>.
(The dashes added for readability by newsreader, remove those in real life.)

Regards

--

Joe
----- Original Message ----- From: "Philip Vallone" <philip(_dot_)vallone(_at_)verizon(_dot_)net>
To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Sent: Saturday, January 27, 2007 3:03 AM
Subject: RE: [xsl] XML to Javascript


Hi Joe,

I figured it out. I had to move the semicolon outside of the <xsl:text>. I
guess in Javascript ";" declares the end of the line and causes a line
break.

Thanks for the help

Phil


-----Original Message-----
From: Philip Vallone [mailto:philip(_dot_)vallone(_at_)verizon(_dot_)net]
Sent: Friday, January 26, 2007 8:31 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] XML to Javascript

Hi Joe,

My construct works perfect when output to HTML.

Here is my desired output:

<script language="JavaScript" type="text/JavaScript">
function CreateProjectExplorer()
{
Initialise();


d =CreateTreeItem( rootCell, "img/folder_closed.gif", "img/folder_open.gif",
"Master MEL", "webaddresshere", "content" );

d2 = CreateTreeItem(d, "img/project.gif", "img/project.gif", "ATA 21", null,
null );
d3 = CreateTreeItem(d2, "img/project.gif", "img/project.gif", "21-01-01 Air
Conditioning Pack Systems - Air Cycle Machine", "21/21-01-01.html" ,
"content" );

d2 = CreateTreeItem(d, "img/project.gif", "img/project.gif", "ATA 22", null,
null );
d3 = CreateTreeItem(d2, "img/project.gif", "img/project.gif", "22-01-A
Autopilot Systems", "22-01-A.html" , "content" );
d3 = CreateTreeItem(d2, "img/project.gif", "img/project.gif", "22-01-B
Autopilot Systems", "22-01-B.html" , "content" );


}
</script>

Here is the xslt:

<script language="JavaScript" type="text/JavaScript">

function CreateProjectExplorer()
{
Initialise();

<xsl:for-each select="$XML1/manual/chapter">
<xsl:text>d = CreateTreeItem( rootCell,
"img/project.gif", "img/project.gif",
"</xsl:text>
<xsl:value-of select="@chaptitle"/>
<xsl:text>", null, null );</xsl:text>
<br/>
<xsl:for-each select="title">
<xsl:text>d2 = CreateTreeItem(d, "img/project.gif",
"img/project.gif", "</xsl:text>
<xsl:value-of select="document(.)//ACM:MELtitle"/>
<xsl:text>", "</xsl:text>
<xsl:value-of select="substring-before(., '.')"/>
<xsl:text>.html</xsl:text>
<xsl:text>" , "content" );</xsl:text>
<br/>
</xsl:for-each>
<br/>
</xsl:for-each>


}
</script>

Here is some XML:

<manual>
<chapter chaptitle="ATA 21">
<title>21-01-01.xml</title>
<title>21-01-A.xml</title>
</chapter>
<chapter chaptitle="ATA 22">
<title>22-01-A.xml</title>
<title>22-01-B.xml</title>
</chapter>
</manual>


-----Original Message-----
From: Joe Fawcett [mailto:joefawcett(_at_)hotmail(_dot_)com]
Sent: Friday, January 26, 2007 7:16 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] XML to Javascript

Not surprising really as br is an HTML element.
When writing script blocks within XSLT it's usually better to wrap them in a

CDATA section so that you don't have to escape characters such as <.
Show an example of the JavaScript you need and some of your source XML.

--

Joe
----- Original Message ----- From: "Philip Vallone" <philip(_dot_)vallone(_at_)verizon(_dot_)net>
To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Sent: Friday, January 26, 2007 11:55 PM
Subject: [xsl] XML to Javascript


Hi all,

I am trying to convert some XML to Javascript for a menu-tree. Is this
possible?

I tried the following XSLT but when I run my construct in the <script> it
doesn't understand <br/>


<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:ACM="www.aviationcontentmanagement.com"
xmlns:fn="http://www.w3.org/2005/xpath-functions";
xmlns:xdt="http://www.w3.org/2005/xpath-datatypes";
xmlns:xs="http://www.w3.org/2001/XMLSchema";>
<xsl:output method="html"/>
<xsl:variable name="XML1" select="/"/>
<xsl:template match="/">
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1"/>
<title>Project Explorer</title>
<link rel="stylesheet" href="./tree.css"/>
<script language="javascript"
src="scripts/tree_view.js"/>
<script language="JavaScript"
type="text/JavaScript">

function CreateProjectExplorer()
{
Initialise();

<xsl:for-each select="$XML1/manual/chapter">
<xsl:text>d =
CreateTreeItem( rootCell, "img/project.gif", "img/project.gif",
"</xsl:text>
<xsl:value-of
select="@chaptitle"/>
<xsl:text>", null, null
);</xsl:text>
<br/>
<xsl:for-each
select="title">
<xsl:text>d2 =
CreateTreeItem(d, "img/project.gif", "img/project.gif", "</xsl:text>
<xsl:value-of
select="document(.)//ACM:MELtitle"/>
<xsl:text>",
"</xsl:text>
<xsl:value-of
select="substring-before(., '.')"/>

<xsl:text>.html</xsl:text>
<xsl:text>" ,
"content" );</xsl:text>
<br/>
</xsl:for-each>
<br/>
</xsl:for-each>


}
</script>
</head>
<style type="text/css">
h2 {font-family:verdana,helvetica,sans-serif;font-size:13pt}
li {font-family:verdana,helvetica,sans-serif;font-size:11pt}
</style>
<body>

</body>
</html>
</xsl:template>
</xsl:stylesheet>


Thanks for the help.

Phil



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>