2

Ok so I have this file that I'm trying to get converted in xsl so I can later make it into rdf data. This is what I have created thus far in xsl file:

<?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="/">
<html>
<head>
        <h1>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="drugs/drug">
        <tr>
            <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>
        </tr>
        </xsl:for-each>
    </tbody>
    </table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

This 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: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...

5
  • version="2.0" : is XSLT 2.0 supported in Firefox ? Commented Jun 28, 2013 at 14:40
  • It is not so I have changed it to version="1.0" and now using Chrome... Commented Jun 28, 2013 at 14:49
  • 1
    If you want to use XSLT 1.0 then you can't use <xsl:result-document> as that was introduced in 2.0. You probably need to use a standalone XSLT 2.0 processor such as Saxon rather than doing the transformation in a browser. Commented Jun 28, 2013 at 14:59
  • In my experience browsers don't handle xslt very well. You might be better served to get a program that actually does the transform for you. Worst case, you can always use Java to compile and transform your xsl for you. Commented Jun 28, 2013 at 15:00
  • I just want to know if I'm staring my xsl file off right. I think that is my problem... Commented Jun 28, 2013 at 19:18

1 Answer 1

1
<drugs xmlns="http://drugbank.ca" ....>

This is your "problem" - because the XML file has a default namespace declaration, all the unprefixed element names in the file are in this namespace. Now in XPath (1.0) expressions, unprefixed names always select nodes that are not in a namespace, so

<xsl:for-each select="drugs/drug">

selects nothing. You need to bind a prefix to the http://drugbank.ca namespace in your stylesheet, and use this prefix in the XPath expressions

<xsl:stylesheet version="1.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="/">
    <!-- ... boilerplate omitted ... -->
    <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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.