Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 28th, 2013, 11:17 AM
Registered User
 
Join Date: Jun 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default XML not reading XSL right

Hello all... I'm having a problem with converting my xml file to xsl using Saxon 9 on Windows 7. So far I have created this xsl file:

Code:
<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output indent="yes"/>
	<xsl:template match="/">
		<xsl:for-each select="drugs/drug">
			<xsl:result-document method = "hml"
					href="file:///C:/Users/X201/Desktop/drugbank/drugbank.xml">
						<xsl:value-of select="'&#xD;'"/>
						<drug>
							<xsl:value-of select="'&#xD;'"/>
							<drugbank-id>
								<xsl:value-of select="'&#xD;'"/>
								<xsl:value-of select="drug/drugbank-id"/>
								<xsl:value-of select="'&#xD;'"/>
							</drugbank-id>
							<xsl:value-of select="'&#xD;'"/>
							<name>
								<xsl:value-of select="'&#xD;'"/>
								<xsl:value-of select="drug/name"/>
								<xsl:value-of select="'&#xD;'"/>
							</name>
							<xsl:value-of select="'&#xD;'"/>
							<description>
								<xsl:value-of select="'&#xD;'"/>
								<xsl:value-of select="drug/description"/>
								<xsl:value-of select="'&#xD;'"/>
							</description>
							<xsl:value-of select="'&#xD;'"/>
							<mechanism-of-action>
								<xsl:value-of select="'&#xD;'"/>
								<xsl:value-of select="drug/mechanism-of-action"/>
								<xsl:value-of select="'&#xD;'"/>
							</mechanism-of-action>
							<xsl:value-of select="'&#xD;'"/>
						</drug>	
						<xsl:value-of select="'&#xD;'"/>			
			</xsl:result-document>
		</xsl:for-each>
	</xsl:template>
</xsl:stylesheet>
When I try to open my xml file in Chrome nothing comes up. This leads me to believe that my xls file is not well-formed and I have found no help on the interwebs.

These are the elements that I want to pull of my xml file and to show up in my browser:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet  type="text/xsl" version="2.0" href="drugbank.xsl"?>

<drugs xmlns="http://drugbank.ca" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" schemaVersion="1.4" xs:schemaLocation="http://www.drugbank.ca/docs/drugbank.xsd">
  <drug type="biotech" created="2005-06-13 07:24:05 -0600" updated="2013-05-12 21:37:25 -0600" version="3.0">
    <drugbank-id>DB00001</drugbank-id>
    <name>Lepirudin</name>
    <description>Lepirudin is identical to natural hirudin except for substitution of leucine for isoleucine at the N-terminal end of the molecule and the absence of a sulfate group on the tyrosine at position 63. It is produced via yeast cells.&#xD;</description>
    <cas-number>120993-53-5</cas-number>
    <synthesis-reference></synthesis-reference>
    <indication>For the treatment of heparin-induced thrombocytopenia</indication>
    <pharmacology>Lepirudin is used to break up clots and to reduce thrombocytopenia. It binds to thrombin and prevents thrombus or clot formation. It is a highly potent, selective, and essentially irreversible inhibitor of thrombin and clot-bond thrombin. Lepirudin requires no cofactor for its anticoagulant action. Lepirudin is a recombinant form of hirudin, an endogenous anticoagulant found in medicinal leeches.</pharmacology>
    <mechanism-of-action>Lepirudin forms a stable non-covalent complex with alpha-thrombin, thereby abolishing its ability to cleave fibrinogen and initiate the clotting cascade. The inhibition of thrombin prevents the blood clotting cascade. </mechanism-of-action>
Any tips would be most appreciated, and thanks...
 
Old June 28th, 2013, 11:56 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I haven't time just now to examine the code in detail but if you open an XML file with an XSLT referenced by an xml-stylesheet processing instruction then the browser will use its own transformation engine. Unless something radical has happened recently Chrome doesn't support version 2.0 of XSLT (nor do the other main browsers) and, even if they did, it's unlikely that they would let you write to the user's file system. You don't seem to need to use xsl:result-document anyway so you could try changing to version 1.0 and simply output the result directly.
__________________
Joe
http://joe.fawcett.name/
 
Old June 28th, 2013, 12:38 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Furthermore, your stylesheet isn't generating HTML, but some XML vocabulary. So running it in the browser isn't going to display anything useful.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old June 28th, 2013, 04:23 PM
Registered User
 
Join Date: Jun 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Figured it out

I got this to work...

Code:
<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"
			xmlns:db="http://drugbank.ca" exclude-result-prefixes="db">
<xsl:output method="html" encoding="UTF-8"/>
<xsl:template match="/">
<html>
<head>
        <h1 align="center">DrugBank Data</h1>
</head>
<body>
	<table border ="2">
	<thead>
		<tr>
			<th>Drugbank Id</th>
			<th>Name</th>
			<th>Description</th>
			<th>Substrate</th>
			<th>Enzymes</th>
			<th>Mechanism Of Action</th>
			<th>Targets</th>
		</tr>
	</thead>
	<tbody>
		<xsl:for-each select="db:drugs/db:drug">
		<tr>
			<td><xsl:value-of select="db:drugbank-id"/></td>
			<td><xsl:value-of select="db:name"/></td>
			<td><xsl:value-of select="db:description"/></td>
			<td><xsl:value-of select="db:substrate"/></td>
			<td><xsl:value-of select="db:enzymes"/></td>
			<td><xsl:value-of select="db:mechanism-of-action"/></td>
			<td><xsl:value-of select="db:targets"/></td>
		</tr>
		</xsl:for-each>
	</tbody>
	</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>





Similar Threads
Thread Thread Starter Forum Replies Last Post
could any one post xsl code to convert plist to xml using xsl andviceversa to plist venkat880 XSLT 0 August 4th, 2011 09:21 AM
Urgent ::Reading two xml files subcontent and adding that to third xml file archleader XSLT 6 August 18th, 2009 03:11 AM
Converting Source Xml into Target Xml Using XSL. alapati.sasi XSLT 3 May 14th, 2007 10:54 AM
Reading ini file in XSL ROCXY XSLT 3 January 9th, 2007 04:37 AM
xml and xsl templates as input to xslt gives xml rameshnarayan XSLT 5 August 3rd, 2005 01:58 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.