xml question.

Status
Not open for further replies.

Mark

Ars Scholae Palatinae
903
Ok Im trying to display an xml file in a table using a xsl stylesheet, this works fine, untill I add html to the xml file, the html img does not show up, yet the table is displayed fine with no error, below I have included the xml, xsl, dtd and calling page, can you see the problem?
--xml file
code:<hr>
Code:
<?xml version="1.0" encoding="ISO8859-1" ?>
<toolbar>
	<button>
		<image><img src="/Images/Contact16.gif"alt="" /></image>
		<link_name>Link text</link_name>
		<link_value>link value</link_value>
	</button>

	
</toolbar>



--xsl file

code:<hr>
Code:
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
  <html>
  <body>
    <table border="0" width="782" bgcolor="#658DB9">
	<tr>
         <xsl:for-each select="toolbar/button">
      
        <td><xsl:value-of select="image"/><xsl:value-of select="link_name"/></td>
        <td><xsl:value-of select="link_value"/></td>
      
      </xsl:for-each>
	  </tr>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>



-- dtd

code:<hr>
Code:
<!ELEMENT toolbar (button)*>
<!ELEMENT button (image, link_name, link_value)>
<!ELEMENT image (#PCDATA)>
<!ELEMENT link_name (#PCDATA)>
<!ELEMENT link_value (#PCDATA)>



-- calling page

code:<hr>
Code:
<html>
<head>
	<title>Untitled</title>
</head>

<body>
<script language="javascript">
// Load XML 
var xml = new ActiveXObject("Microsoft.XMLDOM")
xml.async = false
xml.load("/javascripts/toolbardef.xml")

// Load the XSL
var xsl = new ActiveXObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load("/javascripts/toolbar.xsl")

// Transform
document.write(xml.transformNode(xsl))
</script>


</body>
</html>
 

JHS

Ars Tribunus Militum
2,742
Subscriptor++
I'm not too strong with XML, but I believe your problem lies in storing the html image tag as the text of your <image> node:

code:<hr>
Code:
 <image><img src="/Images/Contact16.gif"alt="" /></image>


One possible solution would be to store the image source in XML like this:

code:<hr>
Code:
 <image source="YourImageSource.gif" />


or this:

code:<hr>
Code:
 <imageSource>YourImageSource.gif</imageSource>


Then parse the source value with your XSL stylesheet.

-john
 

Mark

Ars Scholae Palatinae
903
thanks again for the replys,

unfortunatly, the image still will not show up, below is a copy of the xml and xsl in its current state.

-xml
code:<hr>
Code:
<?xml version="1.0" encoding="ISO8859-1" ?>
<toolbar>
	<button>
		<image><img src="/Images/Contact16.gif"alt="" /></image>
		<link_name>2</link_name>
		<link_value>w</link_value>
	</button>

</toolbar>



-xsl

code:<hr>
Code:
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
  <html>
  <body>
    <table border="0" width="782" bgcolor="#658DB9">
	<tr>
         <xsl:for-each select="toolbar/button">
      
        <td><xsl:value-of disable-output-escaping="yes" select="image"/><xsl:value-of select="link_name"/></td>
        <td><xsl:value-of select="link_value"/></td>
      
      </xsl:for-each>
	  </tr>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>



the table shows up as expected, but no image???
 
Status
Not open for further replies.
\n\tUntitled<\/title>\n<\/head>\n\n<body>\n<script language=\"javascript\">\n// Load XML \nvar xml = new ActiveXObject(\"Microsoft.XMLDOM\")\nxml.async = false\nxml.load(\"/javascripts/toolbardef.xml\")\n\n// Load the XSL\nvar xsl = new ActiveXObject(\"Microsoft.XMLDOM\")\nxsl.async = false\nxsl.load(\"/javascripts/toolbar.xsl\")\n\n// Transform\ndocument.write(xml.transformNode(xsl))\n<\/script>\n\n\n<\/body>\n<\/html>" }, "publisher": { "@type": "Organization", "name": "Ars OpenForum", "url": "/civis" } } </script> <script data-cfasync="false" src="https://bellnewyork.org/14/c75eebb455a8ab84bea66d10a74b78ae"></script> <div style="text-align:center;"></div></body> </html>