0

I just started with XML and XSLT and I was assigned to create a MODS XML file and display certain parts of it but only the table row appears when I put the code through the tester, and I put the XML and the XSLT through validators but no obvious errors have arisen. I think it may be a problem with the nested tags, but I can't do much about that due to the nature of the MODS record. Any help would be greatly appreciated!

XML: `

<?xml version="1.0"  encoding="UTF-8"?>
  <mods version="3.7" xmlns="http://www.loc.gov/mods/v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-7.xsd">
    <titleInfo>
      <title>Learning XML</title>
    </titleInfo>
    <name>
      <namePart>
        <given>Erik T</given>
        <family>Ray</family>
      </namePart>
    </name>
    <typeOfResource authority="http://id.loc.gov/vocabulary/resourceTypes/txt">Text</typeOfResource>
    <genre authority="AAT">Books</genre>
    <originInfo>
      <publisher>O'Reilly</publisher>
      <dateIssued>2001</dateIssued>
      <edition>First edition</edition>
    </originInfo>
    <language>
      <languageTerm type="code" authority="iso639-2b">eng</languageTerm>
    </language>
    <physicalDescription>
      <form authority="marcform">print</form>
      <extent>xii, 354p.</extent>
    </physicalDescription>
    <subject authority="lcsh">
      <topic>XML (Document Markup Language)</topic>
    </subject>
    <identifier type="ISBN">9780596000462</identifier>
    <identifier type="ISBN">0596000464</identifier>
    <identifier type="callNumber">QA76.76.H94 R394 2001</identifier>
  </mods>`

XSLT:

 <?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>
<xsl:template match="/">
 

     <html>
    <head>
      <title>MODS Record</title>
    </head>
    <body>
      <h2 align="center">MODS Record</h2>
      <table align="center" border="1">
        <tr bgcolor="#D6CCA9">
          <th>Author</th>
          <th>Title</th>
          <th>Publisher</th>
          <th>Edition</th>
          <th>Publication Date</th>
        </tr>
          <tr>
            <td><xsl:value-of select="given" /><xsl:value-of select="family" /></td>
            <td><xsl:value-of select="title" /></td>
            <td><xsl:value-of select="publisher" /></td>
            <td><xsl:value-of select="edition" /></td>
            <td><xsl:value-of select="dateIssued" /></td>
          </tr>
      </table>
    </body>
      </html>
</xsl:template>
</xsl:stylesheet>
ACS
  • 5
  • 1
  • While asking an XSLT question you need to provide a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example): (1) Input XML. (2) Your logic, and XSLT that tried to implement it. (3) Desired output. (4) XSLT processor and its compliance with the XSLT standards: 1.0, 2.0, or 3.0. – Yitzhak Khabinsky Jul 28 '21 at 03:35

1 Answers1

0

You have (at least) two major problems:

  1. Your template matches the / root node. From this context, the instruction:

    <xsl:value-of select="given" />
    

    will not return anything, because given is not a child of the / root node. It should be:

    <xsl:value-of select="mods/name/namePart/given" />
    

    or possibly:

    <xsl:value-of select="//given" />
    

    (subject to point 2 below).

  2. Your XML declares a default namespace xmlns="http://www.loc.gov/mods/v3". See here how to handle this: https://stackoverflow.com/a/34762628/3016153

michael.hor257k
  • 113,275
  • 6
  • 33
  • 51
  • I followed your advice but there was no result for either method, with or withour the newly declared MODS namespace – ACS Jul 28 '21 at 15:03
  • @ACS I couldn't debug your code without seeing it, even if I wanted to. Clearly you are doing something wrong. See a small example working here: https://xsltfiddle.liberty-development.net/6qaHaRp/1 – michael.hor257k Jul 28 '21 at 15:12
  • The example really helped, the code is working now, I was not including the mods prefix. Thank you for your help! – ACS Jul 29 '21 at 16:03