Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

turning an XML tree somewhat upside-down

Status
Not open for further replies.

shamesvoice

Technical User
Aug 31, 2007
13
A1
Hello,
I'm a biologist. I've exported a MySQL database as XML. The result is in the order of: Superfamily, family, (subfamily) genus, specific epithet.
An example of my XML file is:

<Chrysidoidea>
<item>
<Family>Bethylidae</Family>
<Subfamily>Bethylinae</Subfamily>
<Genus>Goniozus</Genus>
<SpecificEpithet>claripennis</SpecificEpithet>
</item>
<item>
<Family>Bethylidae</Family>
<Subfamily>Bethylinae</Subfamily>
<Genus>Goniozus</Genus>
<SpecificEpithet>distigmus</SpecificEpithet>
</item>
<item>
<Family>Dryinidae</Family>
<Genus>Aphelopus</Genus>
<SpecificEpithet>atratus</SpecificEpithet>
</item>
<item>
<Family>Embolemidae</Family>
<Genus>Embolemus</Genus>
<SpecificEpithet>ruddii</SpecificEpithet>
</item>
</Chrysidoidea>

Can anyone help me turn this tree upside-down and turn it into the following HTML:

<h1 class="superfamily">Chrysidoidea</h1>

<h2 class="Family">Bethylidae</h2>

<h3 class="Subfamily">Bethylinae</h3>
<h4 class="Genus">Goniozus</h4>
<ul>
<li class="SpecificEpithet">claripennis</li>
<li class="SpecificEpithet">distigmus</li>
</ul>

<h2 class="Family">Dryinidae</h2>

<h4 class="Genus">Aphelopus</h4>
<ul>
<li class="SpecificEpithet">atratus</li>
</ul>

<h2 class="Family">Embolemidae</h2>

<h4 class="Genus">Embolemus</h4>
<ul>
<li class="SpecificEpithet">ruddii</li>
</ul>
 
Change:
Code:
[small]                    <xsl:for-each select="*[substring-before(local-name(),'_') = 'InfraspecificRank' and string-length(text()) &gt; 0]">
                            <xsl:variable name="localNameModifier" select="substring-after(local-name(.),[COLOR=white blue]'SynonymOfScientificName'[/color])"/>[/small]

to:
Code:
[small]                    <xsl:for-each select="*[substring-before(local-name(),'_') = [u]'InfraspecificRank'[/u] and string-length(text()) &gt; 0]">
                            <xsl:variable name="localNameModifier" select="substring-after(local-name(.),[COLOR=white blue]'InfraspecificRank'[/color])"/>[/small]

Without this change, $localNameModifier will not contain the expected '_1' '_2' etc. The color-highlighted string must match the underlined selection in the xsl:for-each.



Tom Morrison
 
Done. And I see the logic to it. It's parallel to other sections. But it doesn't change my HTML output. (Still no display of...) If you'd like to know or see more, please tell me.
 
When referencing a variable in an XPath expression, you must use the [COLOR=white blue]$[/color] operator. This is shown below [COLOR=white blue]highlighted[/color]. Not to do so would have the Xpath expression evaluate to an element named, for example, rankString.

Code:
<xsl:template name="outputRankEpithetAuthor">
    <xsl:param name="rankString"/>
    <xsl:param name="epithetString"/>
    <xsl:param name="authorString"/>
    <xsl:param name="rankClassName"/>
    <xsl:param name="epithetClassName"/>
    <xsl:if test="string-length([COLOR=white blue]$[/color]rankString) &gt; 0">
                <li class="inline">
        <span class="{$rankClassName}">
            <xsl:value-of select="[COLOR=white blue]$[/color]rankString"/>
        </span>
                </li>
        <xsl:if test="string-length([COLOR=white blue]$[/color]epithetString) &gt; 0">
                <li class="inline">
            <span class="{$epithetClassName}">
                <xsl:value-of select="[COLOR=white blue]$[/color]epithetString"/>
            </span>
                </li>
        </xsl:if>
        <xsl:if test="string-length($authorString) &gt; 0">
                <li class="inline">
            <span class="{concat('AuthorYearOf',$epithetClassName)}">
                <xsl:value-of select="$authorString"/>
            </span>
                <br />
                </li>
        </xsl:if>
    </xsl:if>
</xsl:template>

Tom Morrison
 
I was interrupted by a visitor. I forgot to add my mea culpa. [blush]

Fortunately, I do not provide a warranty for my code.

Tom Morrison
 
Thanks. It works fine. No mea culpa necessary, just a caveat emptor, which is understood when writing to such a forum. I'm just glad you could help me (and others).
What remains is mostly styling with CSS. I might still have a question, you never know.
If you're ever in the country...
Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top