Re: [xsl] XHTML html validation

Subject: Re: [xsl] XHTML html validation
From: John Steel <john.steel@xxxxxxxxxxxxxxx>
Date: Fri, 16 Feb 2007 22:18:27 +0000
I think it would help to separate the problems of generating correct XHTML and delivering it to the browser. Small but complete sample input XML and simplified but complete stylesheet would be useful for the generating correct XHTML part.

Thank you, and I apologize for the length of this reply but have simplified it to a smaller working example. I'm using resin 3.0.21 and to kick it off must load a jsp in my browser, I called it dev.jsp:

<%@ page contentType='x-application/xslt' %>
<?xml-stylesheet href='xslt/dev.xsl'?>

<html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">
<body>
 <table>

<faqlist>
<faq>
 <question>
  Question One?
 </question>
 <answer>
  Answer One.
 </answer>
</faq>

<faq>
 <question>
  Question Two?
 </question>
 <answer>
  Answer Two.
 </answer>
</faq>

</faqlist>

 </table>
</body>
</html>

The file xslt/dev.xsl is

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
<xsl:output method="html"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"/>


<xsl:template match='faqlist'>
  <xsl:apply-templates select="*[local-name() != 'faq']" />
  <xsl:apply-templates select="faq" mode="question" />
  <xsl:apply-templates select="faq" mode="answer" />
</xsl:template>

<xsl:template match='faq' mode="question">
<tr>
<td class="mText" style="font-size: 11px">
<a><xsl:attribute name='href'>#<xsl:value-of select="count(preceding-sibling::*) + 1" /></xsl:attribute>
<xsl:value-of select='question' />
</a>
</td>
</tr>
</xsl:template>


<xsl:template match='faq' mode="answer">
        <tr>
          <td width='1%'>&#160;</td>
          <td width='24' class="mText" style="font-size: 11px" >
            &#160;
          </td>
          <td class="mText" style="font-size: 11px" align='left'>
            <xsl:copy-of select='answer' />
            <br/>
            <br/>
          </td>
        </tr>
</xsl:template>

<xsl:template match='*|@*'>
  <xsl:copy>
    <xsl:apply-templates select='node()|@*' />
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>

This generates html which looks like this

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
<html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">

<body> <table>


<faqlist>


<faq>
<question>
Question One?
</question>
<answer>


  Answer One.
 </answer>

</faq>


<faq>
<question>
Question Two?
</question>
<answer>
Answer Two.
</answer>



</faq>



</faqlist>


</table>

</body>

</html>



--
--------------------------
http://www.phonewebcam.com
john.steel@xxxxxxxxxxxxxxx

Current Thread