This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Selecting a descendant child at arbitrary depth
- To: pmcevoy at iona dot com
- Subject: [xsl] Re: Selecting a descendant child at arbitrary depth
- From: Dimitre Novatchev <dnovatchev at yahoo dot com>
- Date: Wed, 14 Mar 2001 02:01:06 -0800 (PST)
- Cc: xsl-list at lists dot mulberrytech dot com
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi Peter,
> <xsl:template match="docBody">
> <xsl:copy-of select="*" />
> </xsl:template>
I just changed this to:
<xsl:template match="docBody">
<xsl:copy-of select="node()" />
</xsl:template>
And when applied to the xml doc in your message,
I get:
**More XHTML tags in here**
If you did not have any element children nodes of "docBody"
(e.g. only text nodes) then this explains the null output.
In your original template only element nodes were specified
in the @select of xsl:copy-of.
Could it be that your HTML was put in CDATA?
Here's the complete stylesheet I used with MSXML3:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" />
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="mainDisplay">
<xsl:apply-templates select=".//docBody" />
</xsl:template>
<xsl:template match="docBody">
<xsl:copy-of select="node()" />
</xsl:template>
</xsl:stylesheet>
Cheers,
Dimitre Novatchev.
Peter McEvoy wrote:
I seem to be going mad today, but I can't seem to do this basic thing:
xml is something like
<mainDisplay>
<document>
**XHTML tags here - arbitrary levels deep
<table>
<tr>
<td>
<docBody>
**More XHTML tags in here**
</docBody>
</td>
</tr>
</table>
**More XHTML tags, but no more docBody tags**
</document>
</mainDisplay>
Now, the mainDisplay element is actually a child of a bigger
tree, but it only occurs once. My
stylesheet can successfully do all it needs to do to set the
mainDisplay as the context node. The
<document> element is the only child of mainDisplay (I know,
that's redundant, but its a legacy
thing (wow, I said "legacy" when refering to XML!!)). The
children of <document> are then any XHTML
tags (in all cases, the first child is a <html> element).
Now, I have invented a tag called <docBody> which surrounds
the XHTML that I am actually interested
in. What I want to do is copy the contents of the <docBody>
to the output, but ignore anything else
that surrounds it:
mainDisplay
+--document
+--html <--ignore
+---... <--ignore
... <--ignore
+--docBody <--ignore
+--copy the contents of this to output
... <--ignore
Because docBody can be at any level below mainDisplay, once I
have successfully got to mainDisplay
as the context node I am trying a rule like this:
<xsl:template match="mainDisplay">
<xsl:apply-templates select=".//docBody" />
</xsl:template>
and then using the template:
<xsl:template match="docBody">
<xsl:copy-of select="*" />
</xsl:template>
I've tried:
<xsl:apply-templates select="descendant::docBody" />
as well, but to no avail.
I know I have got to the mainDisplay template as I've
inserted debugging messages and they come up
on the output. But debugging messages in the docBody template do not.
Can someone give me a hand? I feel like I'm bashing my head
off a wall!!
BTW, using Saxon 5.5.1
C Ya,
Peter McEvoy
Senior Technical Analyst
IONA Technologies
__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - Buy the things you want at great prices.
http://auctions.yahoo.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list