[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Traverse sub tree starting from a particular position

Subject: Traverse sub tree starting from a particular position
From: Graeme Kidd <coolkidd3@xxxxxxxxxxx>
Date: Fri, 15 Apr 2011 03:32:09 +0100
 Traverse sub tree starting from a particular position
Hi all,

I am currently converting the following basic XML to FO:
<root>
    <section>
        <hrline /> Some text
    </section>
    <section>
        <hrdots />Some text <hrline />
    </section>
    <section>
       <p> Some Text <hrline /></p>
    </section>
    <section>
        Some Text
        <hrline />
        <p>
            <sub>Some Text <hrdots /></sub>        
        </p>      
        <sub>Some Text</sub>
    </section>
    <section>
        Some Text <hrline />         
       <img src="smile.gif" />
    </section>
</root>

In the resulting FO file each "section" element ends with an underline,
however there also elements that produce horizontal lines/dots. The idea is to
try and prevent the "section" underline from appearing when there is no text
or elements after the last hrline/hrdots. This is to prevent double lines from
appearing.

The best I have managed so far is to get the last hrline/hrdots element within
the section:
<xsl:template match="section">
    <xsl:variable name="underline">
        <xsl:choose>
            <xsl:when test="descendant::node()[self::hrdot or
self::hrline][last()]">
                <xsl:text>yes</xsl:text>
            </xsl:when>
            <xsl:otherwise>
                <xsl:text>no</xsl:text>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
     <xsl:copy>
        <xsl:attribute name="underline-after">
            <xsl:value-of select="$underline" />
        </xsl:attribute> 
        <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>       
</xsl:template>

What I need to next is traverse the rest of the "section" sub tree to detect
whether there is any more text or nodes appearing after that last
hrline/hrdots element. An example of the output should look like this:

<root>

    <section underline-after="yes">

        <hrline /> Some text

    </section>

    <section underline-after="no">

        <hrdots />Some text <hrline />

    </section>

    <section underline-after="no">

       <p> Some Text <hrline /></p>

    </section>

    <section underline-after="yes">

        Some Text

        <hrline />

        <p>

            <sub>Some Text <hrdots /></sub>        

        </p>      

        <sub>Some Text</sub>

    </section>

    <section underline-after="yes">

        Some Text <hrline />         

       <img src="smile.gif" />

    </section>

</root>

Any help or advice would be much appreciated.

Thanks

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.