开发者

XSLT Sheet Not Being Used

Very next to XML, I've developed an XML sheet, alongside a XSD schema and finally a XSLT sheet to display the content. When I view the XML data sheet in a web browser (done in visual studio) it says the following:

This XML file does not appear to have any style information associated with it. The document tree is shown below.

I've tried different filepaths and messed with the header, by not luck.

XML Data

<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xslt" href="lecturelayout.xslt"?>
<university>
<lesson>
  <subject>Biology</subject>
  <maintopic name="Human Biology">
    <subtopic>Enlarge Hearts</subtopic>
    <subtopic>Heart Valves</subtopic>
  </maintopic>
  <content>
    <sentance>Very long sentance one</sentance>
    <sentance>Very long sentance two</sentance>
    <sentance>Very long sentance three</sentance>
  </content>
</lesson>

  <lesson>
    <subject>Chemistry</subject>
    <maintopic name="Periodic Table">
      <subtopic>Enlarge Hearts</subtopic>
      <subtopic>Heart Valves</subtopic>
    </maintopic>
    <content>
      <sentance>Very long sentance one</sentance>
      <sentance>Very long sentance two</sentance>
      <sentance>Very long sentance three</sentance>
    </content>
  </lesson>
</university>

XSLT Sheet - Note might not be 100% correct, obviously can't test it:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="@* | node()">
      <html>
        <body>
          <h1>Professional Traini开发者_JAVA百科ng Facilities</h1>
            <strong>University: </strong>
            <xsl:for-each select="university/lesson">          
            <xsl:value-of select="subject"/>
          <br/>
          <p>
            <strong>Main Topic: </strong>
            <xsl:value-of select="maintopic=name"/>
          </p>
          <br/>
          <p>
            <strong>Sub Topics: </strong>
            <xsl:for-each select="maintopic">
              <p>
                <xsl:value-of select="subtopic"/>
              </p>
            </xsl:for-each>
          </p>
          <p></p>
          <strong>Content:</strong>
          <xsl:for-each select="content">
            <p>
              <xsl:value-of select="sentance"/>
            </p>
          </xsl:for-each>
          </xsl:for-each> 
          <br/>
        </body>
      </html>
    </xsl:template>
</xsl:stylesheet>

Help greatly appreciated, spent a while research this but just can't find any info on XSLT, unlike XSL.

EDIT: A mate just copied that on his machine(not that he programs) and gets the same result, could someone try it out please? :)


Your type attribute should be text/xsl, not text/xslt. Try

<?xml-stylesheet type="text/xsl" href="lecturelayout.xslt"?>


In addition to adjusting the Processing Instruction @type to type="text/xsl", as suggested by @Matt Gibson, you need to adjust the match expression for your template.

Your template is set to match on every attribute and node() and is producing multiple <html> elements(invalid).

Adjust your template match to the root node:

<xsl:template match="/">
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜