help plz with xslt transformation

Rate It (2)

Last post 05-14-2008 9:32 AM by Bonekrusher. 5 replies.

Sort Posts:

  • help plz with xslt transformation

    05-14-2008, 7:50 AM
    • Member
      22 point Member
    • comphead
    • Member since 08-02-2007, 5:33 AM
    • Posts 131

    HTML(input)

     <html>
    <table class="test">
    <tbody>
    <tr>
    <td>
    </td><td><h3>Text1</h3>
    </td><td></td></tr><tr valign="top">
    <td class="c">1.</td>
    <td class="d"><a href="/map_traffic.xml?mapID=1600&amp;scale=10&amp;mapX=3396238&amp;mapY=6482459">Text2</a></td>
    <td>Text3</td>
    </tr>
    </tbody></table></html>

     

    XSLT

    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" exclude-result-prefixes="xs fn">
        <xsl:output method="xml" encoding="UTF-8" indent="yes" use-character-maps="NBSP"/>
        <xsl:character-map name="NBSP">
            <xsl:output-character character="&amp;" string=";"/>
        </xsl:character-map>
        <xsl:template match="table">
                <xsl:copy>
                    <xsl:apply-templates select="@*"/>
                    <xsl:apply-templates/>
                </xsl:copy>
        </xsl:template>
        <xsl:template match="tr">
                <xsl:copy>
                    <xsl:apply-templates select="@*"/>
                    <xsl:apply-templates/>
                </xsl:copy>
        </xsl:template>
        <xsl:template match="td">
                <xsl:copy>
                    <xsl:apply-templates select="@*"/>
                    <xsl:apply-templates/>
                </xsl:copy>
        </xsl:template>
    </xsl:stylesheet>

     

    Result(XML) 


    <table>Test

    <tr>
    <td>
    </td><td>Text1
    </td><td /></tr><tr>top
    <td>c1.</td>
    <td>dText2</td>
    <td>Text3</td>
    </tr>
    </table>

     

    question at last:)

    How can i modify my XSLT, to make result without class identifiers. so <td>dText2</td> must be <td>Text2</td>.

     

     

  • Re: help plz with xslt transformation

    05-14-2008, 8:07 AM
    • Contributor
      3,945 point Contributor
    • Bonekrusher
    • Member since 08-22-2006, 8:30 PM
    • Posts 895

     Hi,

    Try this:

     

    	<xsl:template match="table">
    		<xsl:copy>
    			<xsl:copy-of select="@*"/>
    			<xsl:apply-templates/>
    		</xsl:copy>
    	</xsl:template>
    	<xsl:template match="tr">
    		<xsl:copy>
    			<xsl:copy-of select="@*"/>
    			<xsl:apply-templates/>
    		</xsl:copy>
    	</xsl:template>
    	<xsl:template match="td">
    		<xsl:copy>
    			<xsl:copy-of select="@*"/>
    			<xsl:apply-templates/>
    		</xsl:copy>
    	</xsl:template>
    </xsl:stylesheet>
    

      When you say:

       <xsl:apply-templates select="@*"/>

     within <xsl:copy>, you are coping the attribute values as content for the element.

    use:

     

    <xsl:copy-of select="@*"/>

     

    If I was helpful, please mark "answered" so I can get credit. Thanks!
  • Re: help plz with xslt transformation

    05-14-2008, 8:16 AM
    • Member
      22 point Member
    • comphead
    • Member since 08-02-2007, 5:33 AM
    • Posts 131

    oh! it's much better

    result is

    - <tr valign="top">
      <td class="c">1.</td>
      <td class="d">text2</td>
      <td>text3</td>
    </tr>
     
    is it possible to remove  attributes also in td tags?
     
    desired output 

    <tr valign="top">

      <td>1.</td>
      <td>text2</td>
      <td>text3</td>
    </tr>
  • Re: help plz with xslt transformation

    05-14-2008, 9:06 AM
    Answer
    • Contributor
      3,945 point Contributor
    • Bonekrusher
    • Member since 08-22-2006, 8:30 PM
    • Posts 895

     yes, just remove:

    <xsl:copy-of select="@*"/>
    Which copies the attributes.
     

     

    If I was helpful, please mark "answered" so I can get credit. Thanks!
  • Re: help plz with xslt transformation

    05-14-2008, 9:11 AM
    • Member
      22 point Member
    • comphead
    • Member since 08-02-2007, 5:33 AM
    • Posts 131

    big thanks! 

  • Re: help plz with xslt transformation

    05-14-2008, 9:32 AM
    • Contributor
      3,945 point Contributor
    • Bonekrusher
    • Member since 08-22-2006, 8:30 PM
    • Posts 895

     You're welcome Big Smile

    If I was helpful, please mark "answered" so I can get credit. Thanks!
Page 1 of 1 (6 items)