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

Discussion in 'XML' started by Philo, May 30, 2004.

  1. Philo

    Philo Guest

    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)
     
    Philo, May 30, 2004
    #1
    1. Advertising

  2. In article <Xns94F98EEF64DA2philojmicrosoftcom@216.196.105.130>,
    Philo <> wrote:

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


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

    -- Richard
     
    Richard Tobin, May 30, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. K Viltersten

    <div ... /> and <div ...></div>

    K Viltersten, Mar 30, 2009, in forum: ASP .Net
    Replies:
    4
    Views:
    755
  2. Augustus
    Replies:
    3
    Views:
    195
    Ken Fine
    Feb 5, 2004
  3. Dwayne Madsen

    Q: Div A inside Div B is larger than Div B

    Dwayne Madsen, Jun 1, 2005, in forum: Javascript
    Replies:
    1
    Views:
    194
    David Dorward
    Jun 1, 2005
  4. mscir
    Replies:
    3
    Views:
    317
    Martin Honnen
    Jun 26, 2005
  5. Sundew Shin
    Replies:
    5
    Views:
    159
Loading...

Share This Page