xsl-list
[Top] [All Lists]

[xsl] Help! How do I find elements through text contents XSLT 1.0

2008-01-24 05:32:44
Hi all,

I've been pulling my hair out over this and I'm sure it has to be simple.

I'm converting HTML to XML (why do all the textbooks only go the other way?)
and I need to identify, say for instance, tables by the contents in the
header row. So, in the inconsistent input file I might have:

<table>
        <tbody>
                <tr>
                        <th>Keyword
...

Or I might equally have:

<table>
        <tr>
                <td><b><i>Keyword
...

Or any combination in between. The question is, how do I consistently
identify this table based on the heading text without knowing the exact node
path. I think I've tried all combinations of contains(), text(), ancestor::
etc.

My original transform which works was limited to two cases and looked like
this: 

        <xsl:template match="body/table">
                <xsl:choose>
                        <xsl:when test="contains(tr[1]/th[1],'Keyword')">
                                <properties>
                                        <xsl:apply-templates select="tr"
mode="prop"/>
                                </properties>
                        </xsl:when>
                        <xsl:when test="contains(tr[1]/td[1],'Keyword')">
                                <properties>
                                        <xsl:apply-templates select="tr"
mode="prop"/>
                                </properties>
                        </xsl:when>

Do I really need to create all possible combinations of hierarchies in order
to pick these tables up?

Thanks in advance for any help or advice you can give,
Richard


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--