L.eung
L.eung

Reputation: 1

XML-XSL Validate Ask

starting xml 10~15 days

while xml-xslt? xml-xsl? studying, i was copying a book but could not vaildate checking.

In XML File, Vaildate Error at line 3, column 11.

This is XML

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="booklist.xsl"?>
<Booklist>
  <Book isbn="20030101">
    <Bookname>XML </Bookname>
    <Author>Pack Mi Young</Author>
    <Publisher>Hanbit</Publisher>
    <Publish_Date>
      <Y>2015</Y>
      <M>10</M>
      <D>15</D>
    </Publish_Date>
    <Page>560</Page>
    <Price>18000</Price>
  </Book>

  <Book isbn="20030102">
    <Bookname>JAVA </Bookname>
    <Author>Cha Sang Min</Author>
    <Publisher>Dankook</Publisher>
    <Publish_Date>
      <Y>2015</Y>
      <M>11</M>
      <D>20</D>
    </Publish_Date>
    <Page>750</Page>
    <Price>28000</Price>
  </Book>
  </Booklist>

In XSL File, Vaildate Error at line 2, column 84.

This is XSL

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/Booklist/Book">
    <h3>Book match template</h3>
    <xsl:apply-templates select="Author:"/>
  </xsl:template>

 <xsl:template match="Author">
    <h3>Author name :</h3>
    <font color='blue'><xsl:value-of select="."/></font>
  </xsl:template>
</xsl:stylesheet>

I do not know why it is not validated.. T.T

for reference, i use XML copy Editor

Upvotes: 0

Views: 55

Answers (1)

zx485
zx485

Reputation: 29022

The error in your XSLT file is on the line

<xsl:apply-templates select="Author:"/>

The : makes your XPath expression invalid. So use

<xsl:apply-templates select="Author"/>

instead.

Also, if you want a valid HTML file you have to make two changes to your XSLT file:

  1. Add an

    <xsl:output method="html" indent="yes" />
    

    as a top-level-element to your xsl:stylesheet. And...

  2. Add a general HTML template matching the root element /:

    <xsl:template match="/">
      <html>
        <body>
          <xsl:apply-templates select="node()|@*" />
        </body>
      </html>
    </xsl:template>
    

Upvotes: 2

Related Questions