Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 8th, 2008, 07:06 AM
Registered User
 
Join Date: Apr 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default html tags to reformed to xhtml standard using xsl

I wanted the html tags to reformed to xhtml standard using xslt.
Like

<html>
<li>
<p>
<p>some para</p> </p>
<li>text<li>[list]<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[list]<li>some sentence </li>
<li> another text </li>
</ul></li>
</html>

Help will be appreciated. thanks in Advance



 
Old April 8th, 2008, 07:13 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

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
 
Old April 10th, 2008, 05:44 AM
Registered User
 
Join Date: Apr 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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>

                                                                                                Line

                                                                                    </strong>

                                                                        </a>

                                                                        <br/>

                                                                        <span>Third Line.</span>

                                                                        <li>

                                                                                    <a href="http://www.r.com/h.aspx">

                                                                                                <strong>

                                                                                                            Foruth line

                                                                                                </strong>

                                                                                    </a>

                                                                                    <br/>

                                                                                    <span>gfgfg</span>

                                                                        </li>

                                                            </li>

                                                </li>

                                    </p>





….

….

Under <p> If <li> is present it should <p>[list]<li>….

As in above case <li><li><li>fd</li>></li></li> should be <li>[list]<li>[list]<li>fd</li></ul></li></ul></li>.

If nest <li> is present without[list][list] should be inserted



 
Old April 10th, 2008, 06:53 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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()">
      [list]<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
 
Old April 11th, 2008, 01:18 AM
Registered User
 
Join Date: Apr 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Michael,
JTidy is written in java . Is it possible to use with c# Asp.net 2.0?
Thanks

 
Old April 11th, 2008, 03:08 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

http://www.devx.com/dotnet/Article/20505/1763/

/- Sam Judson : Wrox Technical Editor -/
 
Old April 11th, 2008, 10:00 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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
 
Old April 17th, 2008, 12:33 AM
Registered User
 
Join Date: Apr 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Please provide the above code in xslt 1.0

 
Old April 17th, 2008, 03:14 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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
 
Old April 19th, 2008, 10:29 AM
Authorized User
 
Join Date: Apr 2008
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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






Similar Threads
Thread Thread Starter Forum Replies Last Post
HTML 4.0 vs. XHTML 1.0 and font sizes Ron Howerton HTML Code Clinic 4 October 14th, 2008 07:05 AM
xHTML to XSL:FO to PDF NotesSensei XSLT 0 September 2nd, 2006 10:02 AM
w3 HTML (XHTML) validation crmpicco HTML Code Clinic 6 June 7th, 2006 07:33 AM
xhtml-tags i xml value-of select patric_jansson XSLT 5 October 3rd, 2005 12:15 PM
How can XSL transform XHTML data into fragments? lamwh XSLT 0 April 19th, 2004 10:15 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.