xsl-list
[Top] [All Lists]

Finding wanted nodes in complex document

2002-10-11 08:04:02
I have a big,complicate, messy xml document (originally a Mozilla
bookmark file that I made into well-formed xml) that I wish to transform
into a lean, mean and clean xml document and I am having some trouble.


Here is part of the document:
<?xml version="1.0" encoding="UTF-8"?>
<bookmarks>
    <DT>
        <H3 ADD_DATE="1032875519" ID="NC:BookmarksRoot#$f68320c5"
            LAST_MODIFIED="1033072101">Consumer Guides</H3>
    </DT>
    <DL>
        <p/>
        <DT>
            <H3 ADD_DATE="1032876491"
ID="NC:BookmarksRoot#$f68320c6">Alabama</H3>
        </DT>
        <DL>
            <p/>
        </DL>
        <p/>
        <DT>
            <H3 ADD_DATE="1032876720" ID="NC:BookmarksRoot#$f68320dc"
LAST_MODIFIED="1033071828">Minnesota</H3>
        </DT>
        <DL>
            <p/>
            <DT>
                <H3 ADD_DATE="1033068848" ID="NC:BookmarksRoot#$c0ebfb0"
                    LAST_MODIFIED="1033077022">Alternative Dispute
Resolution</H3>
            </DT>
            <DL>
                <p/>
                <DT>
                    <H3 ADD_DATE="1032902327"
ID="NC:BookmarksRoot#$f6832141"
LAST_MODIFIED="1033077446">Mediation</H3>
                </DT>
                <DL>
                    <p/>
                    <DT>
                        <A ADD_DATE="1033077149"
                           
HREF="http://www.co.hennepin.mn.us/courts/ConcCt/ccmediation.htm";
                            LAST_CHARSET="ISO-8859-1"
LAST_MODIFIED="1033077270">Mediation in
                            Conciliation Court [From the Hennepin County
District Court]</A>
                    </DT>
                </DL>
                <p/>
                <DT>
                    <A ADD_DATE="1033076751"
HREF="http://www.courts.state.mn.us/adr/adr_info.htm";
                        LAST_CHARSET="ISO-8859-1"
LAST_MODIFIED="1033076778">Minnesota Alternative
                        Dispute Resolution [From the Judicial
System]</A>
                </DT>
                <DT>
                    <A ADD_DATE="1033076913"
                       
HREF="http://www.co.hennepin.mn.us/courts/Arbitration/arbmain.htm";
                        LAST_CHARSET="ISO-8859-1"
LAST_MODIFIED="1033076983"
                        LAST_VISIT="1033077513">What You Need to Know
About Arbitration [From the
                        Hennepin County District Court]</A>
                </DT>
            </DL>
            <p/>
            <DT>
                <H3 ADD_DATE="1033068848" ID="NC:BookmarksRoot#$c0ebfb2"
LAST_MODIFIED="1033070120">Bankruptcy</H3>
            </DT>
            <DL>
                <p/>
            </DL>
            <p/>
            <DT>
                <H3 ADD_DATE="1033068848" ID="NC:BookmarksRoot#$c0ebfb3"
                    LAST_MODIFIED="1033068848">Business Law</H3>
            </DT>
            <DL>
                <p/>
                <DT>
                    <H3 ADD_DATE="1032901666"
ID="NC:BookmarksRoot#$f683211c"
LAST_MODIFIED="1033076330">Corporations</H3>
                </DT>
                <DL>
                    <p/>
                    <DT>
                        <A ADD_DATE="1033076119"
                           
HREF="http://www.state.mn.us/ebranch/mdor/collect/forms/bsl.pdf";
                            LAST_CHARSET="ISO-8859-1"
LAST_MODIFIED="1033076308">Business Successor
                            Liability Fact Sheet [Department of
Revenue]</A>
                    </DT>
                    <DT>
                        <A ADD_DATE="1033076116"
                           
HREF="http://www.state.mn.us/ebranch/mdor/misc/pubs/busentities.pdf";
                            LAST_CHARSET="ISO-8859-1"
LAST_MODIFIED="1033076316">Business Entities:
                            An Overview [Department of Revenue]</A>
                    </DT>
                </DL>
                <p/>
                <DT>
                    <H3 ADD_DATE="1032902430"
ID="NC:BookmarksRoot#$f6832148"
                        LAST_MODIFIED="1033072438">Nonprofit
Corporations*</H3>
                </DT>
                <DL>
                    <p/>
                    <DT>
                        <A ADD_DATE="1033072239"
                           
HREF="http://www.ag.state.mn.us/charities/charDuties.html";
                            LAST_CHARSET="ISO-8859-1"
LAST_MODIFIED="1033072409">Fiduciary Duties of
                            Directors of Charitable Organizations: A
Guide for Board Members [From
                            the Attorney General's Office]</A>
                    </DT>
                    <DD> This guide helps directors understand their
responsibilities as stewards of
                        their organizations. In carrying out their
responsibilities, the law imposes
                        on directors the fiduciary duties of care,
loyalty and obedience to the law.
                        These duties are more generally described in
this guide.</DD>
                    <DT>
                        <A ADD_DATE="1033072224"
                           
HREF="http://www.ag.state.mn.us/charities/Default.htm#New Resources"
                            LAST_CHARSET="ISO-8859-1"
LAST_MODIFIED="1033072289">New Resources For
                            Nonprofits: Sample Policies [From the
Attorney General's Office]</A>
                    </DT>
                    <DD>The Attorney General's Office offers these
sample policies for nonprofits to
                        consider when developing policies to govern
their operations and the conduct
                        of board members, officers, directors and
employees. The policies are
                        offered as guides, and are not meant to
prescribe the exact manner that
                        nonprofits, officers, directors or employees
must act in all situations.</DD>
                </DL>
                <p/>
            </DL>
...................................

OK I told you it was messy.
So first I want to get all the "categories" which I do like this:

<xsl:for-each select="bookmarks/DL/DL/DT/H3">
        <category>
                <xsl:attribute name="name">
                        <xsl:value-of select="."/>
                </xsl:attribute>                
        </category>
</xsl:for-each>
This gives me a nice clean document like this:
  <category name="Alternative Dispute Resolution"/>
  <category name="Bankruptcy"/>
  <category name="Business Law"/>
  <category name="Charities"/>
  <category name="Civil Rights Law"/>
  <category name="Courts"/>
  <category name="Consumer Law"/>
  <category name="Contracts"/>
etc....
Now I want to get the "subcategories" related to the "categories" which
are at "bookmarks/DL/DL/DL/DT/H3" or "../../DL/DT/H3" when compared to
the "category" node.

So what I want is something like this:
<category name="Alternative Dispute Resolution">
        <subcat name="Mediation"/>
</category>
<category name="Bankruptcy"/>
<category name="Business Law">
        <subcat name="Corporations"/>
</category>

I am attempting to do this like this:
<xsl:for-each select="bookmarks/DL/DL/DT/H3">
        <category>
                <xsl:attribute name="name">
                        <xsl:value-of select="."/>
                </xsl:attribute>
                                
                <subcat>
                        <xsl:attribute name="name">
                                <xsl:value-of select="../../DL/DT/H3"/>
                        </xsl:attribute>
                </subcat> 
                        
        </category>
</xsl:for-each>
But this produces this:
<category name="Alternative Dispute Resolution">
    <subcat name="Mediation"/>
</category>
<category name="Bankruptcy">
    <subcat name="Mediation"/>
</category>
<category name="Business Law">
    <subcat name="Mediation"/>
</category>
<category name="Charities">
    <subcat name="Mediation"/>
</category>

What am I doing wrong??


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>