0

I've been going through https://www.w3schools.com/xml/xsl_intro.asp and want to use the same process on my own data but I keep getting errors. What am I missing?

The error in Firefox is enter image description here

The XML is

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
  <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>
    <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>
    <extent>
    <spatial minx="322783.17999999999301508" minz="0" crs="EPSG:28355" maxx="337384.35999999998603016" miny="8170597.66000000014901161" maxz="0" dimensions="2" maxy="8181833.33999999985098839"/>
  </extent>

The XSL is

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<xsl:template match="/">
<html> 
<body>
  <h2><xsl:value-of select="identifier"/></h2>
  <h2><xsl:value-of select="parentidentifier"/></h2>
  <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>
1
  • Your XML is not well-formed as it does not contain a root. Commented Aug 5, 2019 at 0:40

1 Answer 1

1

I added root on your xml

<root>
    <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>
    <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>
    <extent>
        <spatial minx="322783.17999999999301508" minz="0" crs="EPSG:28355" maxx="337384.35999999998603016" miny="8170597.66000000014901161" maxz="0" dimensions="2" maxy="8181833.33999999985098839"/>
    </extent>
</root>

And I tried to modify your xsl like this.

<xsl:stylesheet version="2.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    xmlns="http://www.w3.org/TR/xhtml1/strict">
    <xsl:template match="/">
        <html> 
            <body>
                <h2>
                    <xsl:value-of select="identifier"/>
                </h2>
                <h2>
                    <xsl:value-of select="parentidentifier"/>
                </h2>
                <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>

And everything is working fine.

Sign up to request clarification or add additional context in comments.

2 Comments

Works well in IE -is there anyway to get it to format properly in Firefox as well?
Note that a recent update to Firefox meant that it prevents access to locally stored XSLT files. See stackoverflow.com/questions/57064845/…

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.