[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Embedding html in xml problem

Subject: Re: Embedding html in xml problem
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Sat, 02 Sep 2000 08:31:32 +0100
html in xml problem
Kerry,

>Where I can put lots of html code between <top> and </top> (and all the rest
>too).  So in my xsl I can have something like:
>
>  <xsl:template match="top">
>    <table width="100%" border="0" height="30">
>      <tr>
>        <td>
>        <!-- whatever it takes to grab the values between the top tags,
>value-of or whatever -->
>        </td>
>      </tr>
>    </table>
>  <xsl:call-template name="left"/>
>  <xsl:call-template name="bottom"/>
>  </xsl:template>

You will find XSL a lot easier and more gratifying to use if you think in
terms of the abstract node trees that you're manipulating rather than the
string representation of those trees.  It is very very very rare that you
need to resort to CDATA sections and disable-output-escaping.

If you're wanting to grab all the content within the 'top' element and just
copy it node-for-node, then you're looking for xsl:copy-of.  xsl:copy-of
takes the nodes that you specify (so the HTML content of your 'top'
element) and copies them exactly as they are, with all their attributes and
all their content intact:

  <xsl:template match="top">
    <table width="100%" border="0" height="30">
      <tr>
        <td>
          <xsl:copy-of select="node()" />
        </td>
      </tr>
    </table>
    <xsl:call-template name="left"/>
    <xsl:call-template name="bottom"/>
  </xsl:template>

If the content of the 'top' element has some elements in it that you need
to process (e.g. embedded in the HTML, you have some XML elements that
indicate where the portal user's name should go) then you need to step
through the HTML, applying templates that, by default, copy the elements
and apply templates to their content, with exceptions for those embedded
XML elements:

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

<xsl:template match="insert-user">
  <xsl:value-of select="$user" />
</xsl:template>

Note that the default template (match="*") will match on *any* element.  It
may be worthwhile using namespaces to indicate which elements within your
input are HTML and which are XML, because you can then limit the copying
template to copying only the HTML elements:

<xsl:template match="html:*">
  ...
</xsl:template>

Or the other alternative is to use 'modes' to limit the application of the
template.  So in your 'top' matching template have:

  <xsl:template match="top">
    <table width="100%" border="0" height="30">
      <tr>
        <td>
          <xsl:apply-templates mode="copy" />
        </td>
      </tr>
    </table>
    <xsl:call-template name="left"/>
    <xsl:call-template name="bottom"/>
  </xsl:template>

and make the copying template be both within that mode and apply templates
in that mode:

<xsl:template match="*" mode="copy">
  <xsl:copy>
    <xsl:copy-of select="@*" />
    <xsl:apply-templates mode="copy" />
  </xsl:copy>
</xsl:template>

I hope that this helps,

Jeni

Jeni Tennison
http://www.jenitennison.com/


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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.