0

This is my xsl and xml code.

I am seeing the date 2013.08.20 everytime I run it right at the top and I want to know how to remove it from the output.

XSL stylesheet:

    <?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:zs="http://www.loc.gov/zing/srw/" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>

    <xsl:template match="zs:version">
    </xsl:template>
    <xsl:template match="zs:numberOfRecords">
    </xsl:template>
    <xsl:template match="zs:recordPosition">
    </xsl:template>

    <xsl:template match="zs:record">
    <table>
        <xsl:apply-templates/>
    </table>
    </xsl:template>

    <xsl:template match="zs:recordSchema">
    </xsl:template>
    <xsl:template match="zs:recordPacking">
    </xsl:template>
    <xsl:template match="leader">
    </xsl:template>
    <xsl:template match="controlfield">
    </xsl:template>

    <xsl:template match="datafield[@tag=245]">
        <tr><td>Name: </td><td><b>
            <xsl:for-each select="subfield[@code='a']">
                <xsl:value-of select="text()"/>,&#160;</xsl:for-each></b>
            <xsl:for-each select="subfield[@code='r']">
                <xsl:value-of select="text()"/>,&#160;</xsl:for-each>
            <xsl:for-each select="subfield[@code='g']">
                (<xsl:value-of select="text()"/>),&#160;</xsl:for-each>
            <xsl:for-each select="subfield[@code='d']">
                d. <xsl:value-of select="text()"/>&#160;</xsl:for-each>
        </td></tr>
    </xsl:template>

    <xsl:template match="datafield[@tag=856]">
        <tr><td>Links: </td><td>
            <xsl:element name="a">
               <xsl:attribute name="href">
                <xsl:value-of select="subfield[@code='u']"/>
               </xsl:attribute>
                <xsl:value-of select="subfield[@code='y']"/>
            </xsl:element>
        </td></tr>
    </xsl:template>

    <xsl:template match="datafield[@tag=857]">
        <tr><td>Image: </td><td>
            <xsl:element name="img">
               <xsl:attribute name="src">
                <xsl:value-of select="subfield[@code='u']"/>
               </xsl:attribute>
               <xsl:attribute name="alt">
                <xsl:value-of select="subfield[@code='y']"/>
               </xsl:attribute>
               <xsl:attribute name="width">
                <xsl:text>200</xsl:text>
               </xsl:attribute>
            </xsl:element>
                <xsl:value-of select="subfield[@code='y']"/>
        </td></tr>
    </xsl:template>

</xsl:stylesheet>

XML input:

<zs:searchRetrieveResponse xmlns:zs="http://www.loc.gov/MARC21/slim">
  <zs:version>2013.08.20</zs:version>
  <zs:numberOfRecords>1</zs:numberOfRecords>
  <zs:resultSetId>5031057_1</zs:resultSetId>
  <zs:records>
    <zs:record format="WWI" type="Bibliographic">
      <zs:recordSchema>info:marcXchange</zs:recordSchema>
      <zs:recordPacking>xml</zs:recordPacking>
      <zs:recordData>
        <leader>01136nam 2200301 4500</leader>
        <controlfield tag="001">3/1</controlfield>
        <controlfield tag="003">CaONF</controlfield>
        <controlfield tag="008">150320s2015 onc 00011 eng d</controlfield>
        <controlfield tag="009">NAME</controlfield>
        <datafield tag="245">
          <subfield code="a">Farebrother, George A.</subfield>
          <subfield code="r">Sergeant</subfield>
          <subfield code="g">NiagaraFalls</subfield>
          <subfield code="d">May 26, 1918</subfield>
          <subfield code="u">
            No.2 District Depot. 3rd Bde., Canadian Field Artillery
          </subfield>
          <subfield code="k">1</subfield>
          <subfield code="p">
            NIAGARA FALLS (FAIRVIEW) CEMETERY Ontario,Canada, Family. Sec. M. Lot 76.
          </subfield>
        </datafield>
        <datafield tag="856">
          <subfield code="y">Test complex URL</subfield>
          <subfield code="2">http://</subfield>
          <subfield code="a">www.nflibrary.ca/test/test.aspx?id=</subfield>
          <subfield code="b">farebrother</subfield>
          <subfield code="c">Display=34</subfield>
        </datafield>
        <datafield tag="856">
          <subfield code="y">Canadian Virtual War Memorial</subfield>
          <subfield code="u">
            http://www.veterans.gc.ca/eng/collections/virtualmem/Detail/425501
          </subfield>
        </datafield>
        <datafield tag="856">
          <subfield code="y">War Graves Commission</subfield>
          <subfield code="u">
            http://www.cwgc.org/find-war-dead/casualty/425501/FAREBROTHER, GEORGE ALFRED
          </subfield>
        </datafield>
        <datafield tag="856">
          <subfield code="y">Book of Remembrance</subfield>
          <subfield code="u">
            http://www.veterans.gc.ca/images/collections/books/bww1/ww1405.jpg
          </subfield>
        </datafield>
        <datafield tag="856">
          <subfield code="y">National Archives</subfield>
          <subfield code="u">

          </subfield>
        </datafield>
        <datafield tag="856">
          <subfield code="y">Attestation Papers</subfield>
          <subfield code="u">
          </subfield>
        </datafield>
        <datafield tag="857">
          <subfield code="y">
          </subfield>
          <subfield code="t">
          </subfield>
        </datafield>
        <datafield tag="857">
          <subfield code="u">
          </subfield>
        </datafield>
      </zs:recordData>
      <zs:recordPosition>1</zs:recordPosition>
    </zs:record>
  </zs:records>
</zs:searchRetrieveResponse>
rychrist88
  • 643
  • 6
  • 14
  • 1
    The result you claim is **not** the result obtained when running the code you have provided. The actual result is a blank document. -- it would be helpful if you posted the result that you expect to get. -- Indenting your XSLT code to make it readable would be a nice addition, too. – michael.hor257k Jun 10 '15 at 19:18
  • Now we have twice the input and no XSLT. And still no expected output. – michael.hor257k Jun 10 '15 at 19:46
  • To make a long story short, see this answer posted only an hour ago: http://stackoverflow.com/a/30764820/3016153 – michael.hor257k Jun 10 '15 at 19:55

1 Answers1

0

Your stylesheet seems to have several issues

  • most of your templates do nothing; this is not wrong per se, but it's a problem when it prevents other templates from being executed; in particular, your template for "*" (which is applied to the document element zs:searchRetrieveResponse) does nothing, and the processing just ends here, without any output being produced; if what you really mean is "print nothing and keep processing the content of this element" you should use <xsl:apply-templates/> inside that template (or, even better, eliminate that template, and the built-in one will be used instead)
  • another template matches "zs" (= elements whose name is zs); if you want it to apply to elements in the zs namespace you should use <xsl:template match="zs:*"> (hint: as this template does nothing, and the document element is in the zs namespace, remove this template or you will get no output)
  • the template matching "recordData", which in theory could do something, is not really executed as the recordData element in your input is in the zs namespace, so the match attribute should be "zs:recordData"
  • you use <xsl:output method="html"/> but you are not producing HTML elements; in fact, your templates (should they be executed) only produce text: you should probably use <xsl:output method="text"/>

As you gave no example of the expected output, it's impossible to give you more precise advice.

lfurini
  • 3,729
  • 4
  • 30
  • 48