By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,652 Members | 989 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,652 IT Pros & Developers. It's quick & easy.

XSLT - selecting for <div> but not <table>

P: n/a
How do I select all <div> tags except those which contain a <table> tag
somewhere within them?

Example XML:

<********************** sample input ***********************>

<txtSectionBody>
<div>
<span>
Text Content
</span>
</div>
<div>
<span>
<table>
<tbody vAlign="top">
<tr>
<td>
<div>
<font style="FONT-SIZE: 11pt" size="+
0">
<strong>Dose (mg)</strong>
</font>
</div>
</td>
</tr>
<tr>
<td>
<div>
<font style="FONT-SIZE: 11pt">
250
</font>
</div>
</td>
</tr>
</tbody>
</table>
</span>
</div>
<div>
<font face="undefined">
<span style="FONT-SIZE: 11pt">Various text content</span>
</font>
</div>
<div>
<font face="undefined">
<span style="FONT-SIZE: 11pt">More text content</span>
</font>
</div>
</txtSectionBody>

</********************** sample input ***********************>

Which I need to transform to
<text>
<paragraph>
Text content
</paragraph>
<table>
<tr>
<td>Dose (mg)</td>
</tr>
<tr>
<td>250</td>
</tr>
</table>
<paragraph>
Various text content
</paragraph>
<paragraph>
More text content
</paragraph>
</text>

So I need to select out the div's that *don't* wrap a table and transform
them to paragraph tags, then grab the table out of the div tag and put it
as a child of the document.

I'm trying this:
<text>
<xsl:for-each select="txtSectionBody">
<xsl:for-each select="xhtml:div[not(self::table)]">
<paragraph>
<xsl:value-of select="."/>
</paragraph>
</xsl:for-each>
<xsl:for-each select="xhtml:div/span/table">
<table>
<xsl:for-each select="tbody/tr">
<tr>
<xsl:for-each select="td">
<td>
<xsl:value-of select="."/>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</xsl:for-each>
</xsl:for-each>
</text>

Help?

Philo
(email is first name, middle initial "j", last name. Remove the last name
to reply)
Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
In article <Xn********************************@216.196.105.13 0>,
Philo <ph**************@microsoft.com> wrote:
How do I select all <div> tags except those which contain a <table> tag
somewhere within them?


div[count(.//table) = 0]

-- Richard
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.