Re: [xsl] Processing HTML document.

Subject: Re: [xsl] Processing HTML document.
From: Mike Brown <mike@xxxxxxxx>
Date: Wed, 5 Jun 2002 10:59:40 -0600 (MDT)
Antonio Fiol wrote:
> - My XSLT code should create a whole HTML page, for whose many elements 
> are constant, and the "template" (not in the XSLT sense) for the page is 
> defined (in HTML) by our webmaster. I can ask him to write XHTML, and/or 
> run HTML TIDY on that code to get proper XHTML. However, I need to 
> transform that into an XSLT file. I use an XSLT file called 
> "htmltoxsl.xsl" I created for that purpose.
> 
> - My htmltoxsl.xsl reads a "slightly modified (<?xml...?> added at the 
> beginning, xsl:apply-templates elements added)" (X)HTML page and outputs 
> an XSLT stylesheet containing some IMPORT tags, the HTML code (which 
> contains some xsl:apply-templates inside) inside an <xsl:when test="(no 
> error node is present on the XML file)"> in the template for "/".
>
> - I would like, but I cannot:
> * Ask our webmaster to write XSLT.
> * Include the <?...?> at the beginning of the file and ask our webmaster 
> to edit that (DreamWeaver does not support it).
> * Use HTML Tidy on files containing xsl:apply-templates with optional 
> xsl:with-param. HTML Tidy does not understand them correctly, even 
> adding the tags to the list of supported tags.
> 
> 
> I am partially happy about what I managed to get (the described 
> procedure), but if someone has suggestions on better procedures, do not 
> hesitate to tell me.

Use the document() function to access the XHTML. Do an identity transformation
(like in the XSLT spec under 'Copying') on the XHTML, except when you
encounter a node that indicates something dynamically generated is supposed to
go 'here' -- process those nodes specially.

<html xmlns:special="foo">
  <head>
    <title>xhtml template</title>
  </head>
  <body>
    <h1>generic stuff</h1>
    <table width="100%" cellspacing="20">
      <tr>
        <td>
          <special:data/>
        </td>
        <td>more generic stuff</td>
      </tr>
    </table>
  </body>
</html>

---

<xsl:variable name="xhtml" select="document('foo.xhtml')"/>
<xsl:variable name="orig-xml" select="/"/>

<xsl:template match="/">
  <xsl:apply-templates select="$xhtml" mode="copy"/>
</xsl:template>

<!-- identity transform -->
<xsl:template match="node()|@*" mode="copy">
  <xsl:copy>
    <xsl:apply-templates mode="copy"/>
  </xsl:copy>
</xsl:template>

<!-- replaces <special:data/> with an HTML list -->
<xsl:template match="special:data" xmlns:special="foo">
  <ul>
    <xsl:for-each select="$orig-xml/some/nodes">
      <li><xsl:copy-of select="."/></li>
    </xsl:for-each>
  </ul>
</xsl:template>
  

   - Mike
____________________________________________________________________________
  mike j. brown                   |  xml/xslt: http://skew.org/xml/
  denver/boulder, colorado, usa   |  resume: http://skew.org/~mike/resume/

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread