Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XSLT - selecting for <div> but not <table>

Reply
Thread Tools

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

 
 
Philo
Guest
Posts: n/a
 
      05-30-2004
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)
 
Reply With Quote
 
 
 
 
Richard Tobin
Guest
Posts: n/a
 
      05-30-2004
In article <Xns94F98EEF64DA2philojmicrosoftcom@216.196.105.13 0>,
Philo <(E-Mail Removed)> wrote:

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


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

-- Richard
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT: selecting nodes matching either of 2 criteria Andy Fish XML 5 07-31-2007 10:20 AM
XSLT Selecting characters in string requeth@gmail.com XML 3 09-27-2006 03:34 AM
XSLT: Selecting nodes by comparing data AFTER conversion Ryan Adler XML 2 01-31-2006 09:53 AM
XSLT: selecting a single sub-element to print Tristan Miller XML 5 02-09-2005 01:16 AM
XSLT: selecting the maximal from all counts(newbie) R XML 7 01-17-2005 05:51 PM



Advertisments