|
Subject:
|
html tags to reformed to xhtml standard using xsl
|
|
Posted By:
|
swapbpl
|
Post Date:
|
4/8/2008 7:06:25 AM
|
I wanted the html tags to reformed to xhtml standard using xslt. Like
<html> <li> <p> <p>some para</p> </p> <li>text<li> <ul><li>some sentence </li> <li> another text </li> </ul> </li></li> </html>
Is valid in html but Invalid in xhtml It should re formatted using xslt
<html> <li> <p>some para</p> </li> <li>text <ul><li>some sentence </li> <li> another text </li> </ul></li> </html>
Help will be appreciated. thanks in Advance
|
|
Reply By:
|
Martin Honnen
|
Reply Date:
|
4/8/2008 7:13:56 AM
|
It is not clear to me what you want to achieve. Neither the first nor the second sample is valid XHTML, there are several things missing: You need the XHTML namespace http://www.w3.org/1999/xhtml, you need a head and a body element, you need a ul parent element for the li elements.
-- Martin Honnen Microsoft MVP - XML
|
|
Reply By:
|
swapbpl
|
Reply Date:
|
4/10/2008 5:44:15 AM
|
Hi,
In my html file I have following code..
…..
….
<p>
<li>
<a href="asd.aspx">test</a>
<br/>
<span>second line.</span>
<li>
<a href="http://www.cv.com/f.aspx">Third Line</a>
<br/>
<span>Cross-browser </span>
</li>
<li>
<a href="http://www.d.com/d.aspx">
<strong>
<font>Line</font>
</strong>
</a>
<br/>
<span>Third Line.</span>
<li>
<a href="http://www.r.com/h.aspx">
<strong>
<font>Foruth line</font>
</strong>
</a>
<br/>
<span>gfgfg</span>
</li>
</li>
</li>
</p>
….
….
Under <p> If <li> is present it should <p><ul><li>….
As in above case <li><li><li>fd</li>></li></li> should be <li><ul><li><ul><li>fd</li></ul></li></ul></li>.
If nest <li> is present without <ul> <ul> should be inserted
|
|
Reply By:
|
mhkay
|
Reply Date:
|
4/10/2008 6:53:34 AM
|
Wouldn't you be better off using a tool such as JTidy? Cleaning up bad HTML is a fairly major project, and you seem to be tackling it in a fairly ad-hoc manner.
Having said that, if you want to group consecutive li elements that aren't children of a ul, you can do it like this:
<xsl:template match="p"> <xsl:for-each-group select="*" group-adjacent="boolean(self::li)"> <xsl:choose> <xsl:when test="current-grouping-key()"> <ul><xsl:copy-of select="current-group()"/></ul> </xsl:when> <xsl:otherwise> <xsl:copy-of select="current-group()"/> </xsl:otherwise> </xsl:for-each-group> </xsl:template>
But that's only one of very many rules you will have to apply.
Michael Kay http://www.saxonica.com/ Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|
Reply By:
|
swapbpl
|
Reply Date:
|
4/11/2008 1:18:32 AM
|
Hi Michael, JTidy is written in java . Is it possible to use with c# Asp.net 2.0? Thanks
|
|
Reply By:
|
samjudson
|
Reply Date:
|
4/11/2008 3:08:26 AM
|
http://www.devx.com/dotnet/Article/20505/1763/
/- Sam Judson : Wrox Technical Editor -/
|
|
Reply By:
|
mhkay
|
Reply Date:
|
4/11/2008 10:00:27 AM
|
I believe that all machines that run .NET will also run Java. So yes. If you really want you can cross-compile to .NET using IKVMC, but it depends what you want to achieve.
Michael Kay http://www.saxonica.com/ Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|
Reply By:
|
swapbpl
|
Reply Date:
|
4/17/2008 12:33:30 AM
|
Please provide the above code in xslt 1.0
|
|
Reply By:
|
mhkay
|
Reply Date:
|
4/17/2008 3:14:02 AM
|
What do you mean by "the above code"? My posting of 2008-04-10?
If you want to do positional grouping in XSLT 1.0 it can be done, but it's not easy - it requires a good understanding of how to write recursive templates. I'm afraid that writing this kind of code in XSLT 1.0 is no pleasure - I don't like working with one hand tied behind my back - so I'll leave it to you. Search for "positional grouping".
Michael Kay http://www.saxonica.com/ Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|
Reply By:
|
Alain COUTHURES
|
Reply Date:
|
4/19/2008 10:29:19 AM
|
Tidy is perfect for converting HTML to XHTML so this program has many options. If it is just for parsing purposes, a simple function is enough. I have written such a function in C# : http://sourceforge.net/projects/light-html2xml
|
|
Reply By:
|
tims
|
Reply Date:
|
4/22/2008 11:01:05 PM
|
I could not get the way out in xslt1.0. I need this in xslt 1.0.
|
|
Reply By:
|
Alain COUTHURES
|
Reply Date:
|
4/23/2008 2:11:50 AM
|
Since it seems this 'HTML' document is, in fact, a well-formed XML document, something like that could do the trick if there is no element between the li elements :<xsl:template match="li">
<xsl:choose>
<xsl:when test="name(ancestor::*[1])!='ul'">
<xsl:if test="not(preceding-sibling::li)">
<ul>
<xsl:for-each select=". | following-sibling::li">
<li><xsl:apply-templates/></li>
</xsl:for-each>
</ul>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<li><xsl:apply-templates/></li>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
|
|
Reply By:
|
tims
|
Reply Date:
|
5/8/2008 5:38:14 AM
|
When used the above code Original List . first line . second line . third line
Becomes Original List .first List . Second List . third list
Nesting level should remain same
|