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 July 7th, 2005, 07:28 AM
Registered User
 
Join Date: Jul 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSLT help!!!

I am having trouble with using XSLT. It's confusing as to why but basically I have valid html and I am transforming it to my own xml. What I want to do is the following:

I have an html table. There are many elements in a <td> element.
For example it may look like this:

<td>
<p>this is a test</p>
<br/>
<a href="link">this is a link</a>
<a href="link2">this is another link</a>
<br/>

<br/>
</td>

What I want to do is that everytime there is a <br/>, end the current panel and start a new panel.

So it would look like:

<surroundingTag>
 <myOwnTag>
  <p>this is a test</p>
 </myOwnTag>
 <myOwnTag>
  <a href="link">this is a link</a>
  <a href="link2">this is another link</a>
 </myOwnTag>
 <myOwnTag>

 </myOwnTag>
</surroundingTag>


Right now I have this:

...

<xsl:template match="tr">
  <xsl:for-each select=".">
   <surroundingTag>
   <xsl:apply-templates select="td"/>
   </surroundingTag>
  </xsl:for-each>
</xsl:template>

<xsl:template match="td">

<xsl:for-each select=".">
 <myOwnTag>
  <xsl:apply-templates/>
 </myOwnTag>
</xsl:for-each>

</xsl:template>

I want to do something like this...although I know it doesn't work. When a <br/> is read. I want to close the current tag by </myOwnTag>, then start a new tag by <myOwnTag>...

<xsl:template match="//table//br">

</myOwnTag>
<myOwnTag>

</xsl:template>

I know that doesn't work. I am new to this. Any ideas how to accomplish this??

Any help is appreciated. Thanks!






 
Old July 11th, 2005, 09:55 AM
Authorized User
 
Join Date: Jun 2003
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rushman
Default

Here you go... Altough I don't think it's very "elegant" to use <xsl:text> to output tags, this stylesheet follows your basic idea. IMHO you should just ignore the <br/> and use another mean to enclose the same tags in <myOwnTag> elements...

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <myDoc>
            <xsl:apply-templates/>
        </myDoc>
    </xsl:template>
    <xsl:template match="//tr">
        <xsl:for-each select=".">
            <surroundingTag>
                <xsl:apply-templates select="td"/>
            </surroundingTag>
        </xsl:for-each>
    </xsl:template>
    <xsl:template match="td">
        <xsl:for-each select=".">
            <myOwnTag>
                <xsl:apply-templates/>

            </myOwnTag>
        </xsl:for-each>
    </xsl:template>
    <xsl:template match="//table//br">
        <xsl:text disable-output-escaping="yes">&lt;/myOwnTag></xsl:text>
        <xsl:text disable-output-escaping="yes">&lt;myOwnTag></xsl:text>
    </xsl:template>
    <xsl:template match="p|a|hr">
        <xsl:copy-of select="."/>
    </xsl:template>
</xsl:stylesheet>

Dijkstra's law on Programming and Inertia:

If you don't know what your program is supposed to do, don't try to write it.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Generating XSLT with XSLT stonis XSLT 3 April 1st, 2008 08:17 PM
General XSLT Questions in the XSLT Forum jminatel BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition ISBN: 978-0-470-19274-0 0 March 31st, 2008 07:50 PM
Can XSLT read DTD/schema and Generate XSLT.. ROCXY XSLT 1 November 6th, 2006 09:39 AM
dynamic xslt -> xslt creation namespace problem jkmyoung XSLT 2 July 15th, 2006 12:42 AM
xslt with an xslt outputfile alleycat XSLT 4 February 20th, 2006 09:56 AM





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