Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jun 2013
    Thanked 0 Times in 0 Posts

    Transformation not working

    Hello... so I have a XML file that I want to be transformed using XSLT, but i don't understand why I is not working right. I have rewritten the xsl file over at least 4 times to no avail. I have a feeling that what I have in my XSL file may not be well-formed. I would appreciate any help.

    Heres my XSL 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">
    <xsl:output method="html" encoding="UTF-8"/>
    <xsl:template match="/">
            <h1>DrugBank Data</h1>
    	<table border ="2">
    			<th>Drugbank Id</th>
    			<th>Mechanism Of Action</th>
    		<xsl:for-each select="drugs/drug">
    			<td><xsl:value-of select="drugbank-id"/></td>
    		        <td><xsl:value-of select="name"/></td>
    			<td><xsl:value-of select="description"/></td>
    			<td><xsl:value-of select="substrate"/></td>
    			<td><xsl:value-of select="enzymes"/></td>
    			<td><xsl:value-of select="mechanism-of-action"/></td>
    			<td><xsl:value-of select="targets"/></td>
    And here is my a sample of my XML file:
    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet  type="text/xsl" version="2.0" href="drugbank.xsl"?>
    <drugs xmlns="http://drugbank.ca" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" schemaVersion="1.4" xsi: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">
        <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>
        <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>
    I'm not getting anything to show up in my HTML file. I'm using saxon9 to do the transformation, thanks...

  2. AdSlot6
  3. #2
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Splendora, Texas, United States of America
    Thanked 301 Times in 295 Posts
    Quote Originally Posted by Vandy.Chan View Post
    Hello... so I have a XML file that I want to be transformed using XSLT, but i don't understand why I is not working
    Declare your namespace...

    <xsl:stylesheet ... xmlns:d="http://drugbank.ca">
    ... and reference it...

    <xsl:for-each select="d:drugs/d:drug">
    		<td><xsl:value-of select="d:drugbank-id"/></td>
    		<td><xsl:value-of select="d:name"/></td>
    		<td><xsl:value-of select="d:description"/></td>
    		<td><xsl:value-of select="d:substrate"/></td>
    		<td><xsl:value-of select="d:enzymes"/></td>
    		<td><xsl:value-of select="d:mechanism-of-action"/></td>
    		<td><xsl:value-of select="d:targets"/></td>
    Also, your XML and HTML has errors:
    • There's no version pseudo-attribute defined for the xml-stylesheet processing instruction.
    • The correct media types for XSLT is application/xml or application/xslt+xml (not text/xsl).
    • An HTML document must begin with <!doctype html> or <!doctype html system "about:legacy-compat">. This can be done with...
      <xsl:output ... doctype-system="about:legacy-compat"/>
    • h1 elements are disallowed within the head element; use the (required) title element instead.
    • The border attribute is non-conforming. Use CSS:
      	table, th, td { border: 2px solid; }
    For every complex problem, there is an answer that is clear, simple, and wrong.


Posting Permissions

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