ASPN ActiveState Programmer Network  
ActiveState, a division of Sophos
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups
Submit Recipe
My Recipes

All Recipes
All Cookbooks


View by Category

Title: Verbatim Copying of Embedded HTML (HTMLViewer)
Submitter: Bill Bell (other recipes)
Last Updated: 2004/03/21
Version no: 1.0
Category: Using HTML

 

Not Rated yet


Description:

Some XML sources contain HTML fragments which simply need copying from the source into the output. Here is the essential idea.

Source: Text Source

<!--XSLT code-->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="html"/>
    
    <xsl:template match = "html">
        <xsl:copy-of select="* |text()"/>
        <br/>
    </xsl:template>

</xsl:stylesheet>

<!--typical XML to be processed-->

<?xml-stylesheet type="text/xsl" href="essential.xsl"?>
<emailLinks>

    <emailLink>
        <html>
            <a href="mailto:bonzo@hotmail.com">Bonzo</a>
        </html>
    </emailLink>

    <emailLink>
        <html>
            <a href="mailto:eliza@hotmail.com">Eliza</a>
        </html>
    </emailLink>

</emailLinks>

The license for this recipe is available here.

Discussion:

This recipe is drawn from an example that is supplied in the Microsoft "XSLT Samples Viewer 1.0," which is available free as a download. Incidentally, I find this an extremely useful source, even if many of the descriptions of the codes seem nearly unintelligible to mere mortals such as myself.



Add comment

Number of comments: 2

Also Usefull, Luke Dalessandro, 2005/06/28
I've also found the construction:

<xsl:template match="html//*" priority="0">
   <!-- Copy all random html tags that exist in html sections,
        Including nested tags! -->
   <xsl:copy>
      <xsl:copy-of select="@*" />
      <xsl:apply-templates />
   </xsl:copy>
</xsl:template>
very helpful in these circumstances.

Add comment

Copy Everything, Scott Penrose, 2006/04/17
If you don't care about the individual type, eg: HTML, and you just want to copy everything here it is...

<xsl:template match="@*|node()">
        <xsl:copy>
                <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
</xsl:template>

Add comment



Highest rated recipes:

1. Search and Replace

2. Generating a newline

3. Internationalization ...

4. Restricting processing ...

5. Result Pagination with ...

6. Fetching information ...

7. Getting text children of ...

8. Creating empty elements




Privacy Policy | Email Opt-out | Feedback | Syndication
© 2006 ActiveState Software Inc. All rights reserved.