GeorgeC
GeorgeC

Reputation: 1037

Create style sheet for xml to html

I am trying to create a style sheet to format a qgis metadata (qmd) xml document in html. I'm new to the process but have been trying the following and it's not associating the stylesheet appropriately.

The QMD has

<!DOCTYPE qgis PUBLIC 'http://mrcc.com/qgis.dtd' 'SYSTEM'>
<?xml-stylesheet href="Sewerage_Manholes_InspectionShafts.xsl" type="text/xsl" ?>
<qgis version="3.9.0-Master">
  <identifier>Z:/My Drive/Mangoesmapping/Spatial Projects/2019/DSC/132_Ongoing_Asset_Updates/Working/Sewerage_Updates/Sewerage_Manholes_InspectionShafts.TAB</identifier>
  <parentidentifier>Sewerage Manhole Infrastructure</parentidentifier>
  <language>AUS</language>
  <type>dataset</type>
  <title>Sewerage Manholes within Douglas Shire Council</title>
  <abstract>Sewerage Manholes within Douglas Shire Council. Most data has been updated based on field work, review of existing AsCon files and discussion with council staff responsible for the assets in 2018/2019. In Port Douglas most of the infrastructure has been surveyed in. </abstract>
  <keywords vocabulary="gmd:topicCategory">
    <keyword>Infrastructure</keyword>
    <keyword>Sewerage</keyword>
  </keywords>
  <keywords vocabulary="undefined 2">
    <keyword>Sewerage</keyword>
  </keywords>
  <keywords vocabulary="undefined 3">
    <keyword>Manholes</keyword>
  </keywords>
  <keywords vocabulary="undefined 4">
    <keyword>Douglas</keyword>
  </keywords>
  <keywords vocabulary="undefined 5">
    <keyword>Queensland</keyword>
  </keywords>
  <contact>
    <name>GIS</name>
    <organization>Douglas Shire Council</organization>
    <position>Finance, Procurement &amp; ICT | Douglas Shire Council</position>
    <voice></voice>
    <fax></fax>
    <email>[email protected]</email>
    <role>Team Leader ICT &amp; Process Improvement</role>
  </contact>
  <links/>
  <history>History</history>
  <fees></fees>
  <rights>Council does not warrant the accuracy of the Data and the Customer
must verify the accuracy of the Data before placing reliance on the Data.</rights>
  <rights>The User indemnifies Council, its employees and agents from any
loss or damage suffered by the Customer or any person or entity, arising
from or in connection with the use/misuse of the Data.</rights>
  <license>The Council is the absolute owner of all intellectual property rights,
including copyright, in the Council’s Data Base (other than DCDB) and
that this Agreement confers no proprietary rights whatsoever in the
Council’s Data Base on the Customer.</license>
  <encoding></encoding>
  <crs>
    <spatialrefsys>
      <proj4>+proj=utm +zone=55 +south +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs</proj4>
      <srsid>2449</srsid>
      <srid>28355</srid>
      <authid>EPSG:28355</authid>
      <description>GDA94 / MGA zone 55</description>
      <projectionacronym>utm</projectionacronym>
      <ellipsoidacronym>GRS80</ellipsoidacronym>
      <geographicflag>false</geographicflag>
    </spatialrefsys>
  </crs>
  <extent>
    <spatial minx="322783.17999999999301508" minz="0" crs="EPSG:28355" maxx="337384.35999999998603016" miny="8170597.66000000014901161" maxz="0" dimensions="2" maxy="8181833.33999999985098839"/>
    <temporal>
      <period>
        <start></start>
        <end></end>
      </period>
    </temporal>
  </extent>
</qgis>

The xsl has

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

this should be the value from the title tag

</head>
<body>
<h1>Keywords: </h1>    
</body>
    <table style="width:100%;"
        <xsl:for-each select="/keywords>
            <tr>
                <td><xsl:value-of select="keyword"/></td>

Each of the keywords in a table

            </tr>

Value for abstract

        </xsl:for-each>

</html>    
</xsl:template>    
</xsl:stylesheet>

and even this basic code doesn't work -nothing is shown when I load it in a browser.

What am I missing?

Once I do this I want to grab values like "//spatial/@maxx" as well.

Upvotes: 0

Views: 115

Answers (1)

Ajeet Singh
Ajeet Singh

Reputation: 1076

Try this:-

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
    <html>
        <head>
            <title>
                <xsl:value-of select="//title"/>
            </title>
        </head>
        <body>
            <h1>Keywords: </h1>
        <xsl:for-each select="//keywords">
            <table style="width:100%;">
                <tr>
                    <xsl:for-each select="keyword">
                        <td>
                            <xsl:value-of select="current()"/>
                        </td>
                    </xsl:for-each>
                </tr>
            </table>
        </xsl:for-each>
        <xsl:value-of select="//spatial/@maxx"/>
        </body>
    </html>
</xsl:template>
</xsl:stylesheet>

Upvotes: 1

Related Questions