Search code examples
c#xmlxsltxslt-1.0spire.doc

parsing text of multiple tags under single tag in xslt


I am working in xml and xslt. I have following xml

<book>
  <book-part book-part-type="chapter" book-part-number="1" id="PT-161_ch_1">
 <book-meta>
 <book-title-group>
        <book-title>Software&#x002d;Hardware Integration in Automotive Product Development</book-title>
      </book-title-group>
    </book-meta>
    <book-part-meta>
     <title-group>
    <title>
      <bold>2008-21-0043</bold>
      </title>
      </title-group>
     </book-part-meta>
<body>
   <sec id="ch1.1">
    <title>INTRODUCTION</title>
    <p>The trends of increased functionality, improved performance, reduced size and increased complexity continue to evolve in the automotive electronics market. New system architectures are providing the performance and memory capability necessary to keep up with the hardware performance and software growth required by the automotive market trends. All of this technology growth implies a higher product cost and increased engineering effort required to develop these new products.</p>
   </sec>
</body>

I have following XSLT

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" omit-xml-declaration="yes" doctype-public="-//W3C//DTD HTML 4.0 Transitional//EN"/>

<xsl:template match="book-part">

<html>
  <head>

  </head>
  <body>
    <xsl:for-each select="book-meta">
      <p>
        <b>
          <xsl:value-of select="book-title-group/book-title"/>
        </b>
      </p>
    </xsl:for-each>
    <xsl:for-each select="book-part-meta">
      <p>
        <b>
          <xsl:value-of select="title-group/title"/>
        </b>
      </p>
    </xsl:for-each>
    <xsl:for-each select="body/sec">
      <p>
        <ol>
          <li>
        <b>
          <div>
          <xsl:value-of select="title"/>
          </div>
        </b>
          </li>
        </ol>
        <xsl:for-each select="p">
          <xsl:value-of select="text()"/>
        </xsl:for-each>
      </p>
      <xsl:for-each select="sec">
        <p>
          <ol>
            <li>
              <b>
                <div>
            <xsl:value-of select="title"/>
                </div>
              </b>
            </li>
          </ol>
          <xsl:value-of select="p"/>
        </p>
      </xsl:for-each>
    </xsl:for-each>
    </body>
    </html>
  </xsl:template>
  <xsl:template match="text()[parent::xref]"/>
</xsl:stylesheet>

I have to convert this XML to EPub. In order to convert it to Epub, i am first converting it to html using XSLCompiledTransform and then html to xhtml and then using Spire.doc, this xhtml isbeing converted to Epub.

But while transforming xhtml to Epub Spire.doc is giving following error

The element 'body' in namespace 'http://www.w3.org/1999/xhtml' cannot contain text.List of possible elements expected: 'http://www.w3.org/1999/xhtml:p h1 h2 h3 h4 h5 h6 div ul ol dl pre hr blockquote...

I am not getting exactly what changes i should make in xslt in order to parse "text()".


Solution

  • I think your stylesheet has generated invalid XHTML, and the second phase of processing (XHTML to Epub conversion) is therefore rejecting it. The first stage in identifying this problem is to look at the XHTML you have generated.

    Using schema-aware XSLT can make debugging a lot easier - it allows you to validate the XHTML output as it is being produced, and with luck it will give you the location in the stylesheet that produces the offending content.