Convert XML to HTML (unlike xhtml)

I want to convert some xml to HTML, which has the following format:

<TR> <TD> col1 <TD> col2 <TD> col3 </TR>

Note: Output HTMLcomplete with optional closing tags omitted. This is problem and the reason this question exists.

The XSL snippet I'm using is:

<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output 
    doctype-system='http://www.w3.org/TR/html4/strict.dtd'
    doctype-public='-//W3C//DTD HTML 4.01//EN'
    indent='yes'
    method='html'
    />
   ...
   <xsl:for-each select="/">  
      <TR><TD><xsl:value-of select="col1"/><TD><xsl:value-of select="col2"/><TD><xsl:value-of select="col3"/></TR>
   </xsl:for-each>

You can see that the guts of XSL match my desired HTML (wrapped for readability):

<TR>  <TD><xsl:value-of select="Column1"/>
      <TD><xsl:value-of select="Column2"/>
      <TD><xsl:value-of select="Column3"/> </TR>

Note: Those of you who know the error I get from XSLT: hopefully already know the answer.

XSL (, , xml), :

"TR" "TD".

. :

<TD><xsl:value-of select="Column3"/> </TR>

i TD TR. , :

xml HTML, , HTML xml?

.


, , XSL (, ):

<TR>    <TD><xsl:value-of select="col1"/></TD>
        <TD><xsl:value-of select="col2"/></TD>
        <TD><xsl:value-of select="col3"/></TD>   </TR>

, xsl:output method='html', HTML </TD>, . , :

<TR><TD>col1</TD><TD>col2</TD><TD>col3</TD></TR>

, , , . , . , "" , , :

<BR/>

<BR></BR>

<BR> HTML, , HTML , <BR>.

+5
4

:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="text"/>

 <xsl:template match="/*">
   &lt;TR>&lt;TD><xsl:value-of select="col1"/>&lt;TD><xsl:value-of select="col2"/>&lt;TD><xsl:value-of select="col3"/>&lt;/TR>
 </xsl:template>
</xsl:stylesheet>

XML-:

<t>
 <col1>1</col1>
 <col2>2</col2>
 <col3>3</col3>
</t>

:

   <TR><TD>1<TD>2<TD>3</TR>
+2

, - , . , , , .

, ?

. method="html" <BR/> <BR>:

XSLT ( <BR/>):

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output 
doctype-system='http://www.w3.org/TR/html4/strict.dtd'
doctype-public='-//W3C//DTD HTML 4.01//EN'
indent='yes'
method='html'
/>

<xsl:template match="/">
<HTML><BODY>
    <TR>
        <xsl:apply-templates/>
    </TR>
    <BR/> <!-- HERE -->
</BODY></HTML>
</xsl:template>

<xsl:template match="item">
    <TD><xsl:value-of select="."/></TD>
</xsl:template>

</xsl:stylesheet>

Input:

<root>
<item>one</item>
<item>two</item>
</root>

( <BR>):

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<HTML><BODY>
<TR>
<TD>one</TD>
<TD>two</TD>
</TR>
<BR> <!-- HERE -->
</BODY></HTML>
+2

"HTML"? , HTML, (.. <BR>, <img>).

If you still don’t like the way the XSLT engine serializes HTML output, you can install <xsl:output method="text">and build the “HTML” you want

&lt;TR>&lt;TD><xsl:value-of select="col1"/>&lt;TD><xsl:value-of select="col2"/>&lt;TD><xsl:value-of select="col3"/>&lt;/TR>

which produces:

<TR><TD>col1<TD>col2<TD>col3</TR>  
+1
source

Yang, have you tried <xsl:output method="text">?

http://www.w3schools.com/xsl/el_output.asp

0
source

All Articles