This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: using document() to read HTML


Hi Rosa,

> thanx to David for the hyperlink replies. Here's another one: when u
> read in a HTML page say using document(top.htm) - don't know any
> other way - , I presume it's like a pointer pointing to the
> beginning node of that file. Because I want sections of the HTM file
> or even the whole HTM file to be in front of some HTML which will be
> translated by XSL.

If you do:

  <xsl:copy-of select="document('top.htm')" />

then you will get a copy of the entire file at the point where you
place the instruction.

If you're interested in a specific part of that document, then you can
select nodes in it using an XPath in just the same way as you can
select nodes in the source XML document.  For example:

  <xsl:copy-of select="document('top.htm')/*/BODY/TABLE[1]/TR" />

will copy all the TR elements of the first TABLE element within the
BODY element of your HTML document.

If you want to determine what to copy on the fly, then you can apply
templates to the external HTML document in just the same way as you
can to the source document.  So you could do:

  <xsl:apply-templates select="document('top.htm')/*" />

and then have templates that perform the relevant copying:

<xsl:template match="TR">
   <xsl:copy-of select="." />
</xsl:template>

One thing to watch out for if you take this last approach is that
there might be clashes between templates you're using for the main
source XML document and the templates you want to use for the external
HTML document. If this is a problem, it might be best to use modes to
distinguish between the two.  For example:

  <xsl:apply-templates select="document('top.htm')/*" mode="insert" />

and then:

<xsl:template match="TR" mode="insert">
   <xsl:copy-of select="." />
</xsl:template>

I hope that helps,

Jeni

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



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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]