| Subject: [xsl] Traverse sub tree starting from a particular position From: Graeme Kidd <coolkidd3@xxxxxxxxxxx> Date: Fri, 15 Apr 2011 03:32:09 +0100 | 
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 | 
|---|
| 
 | 
| <- Previous | Index | Next -> | 
|---|---|---|
| Re: [xsl] mode, Imsieke, Gerrit, le- | Thread | Re: [xsl] Traverse sub tree startin, Brandon Ibach | 
| Re: [xsl] mode, G. Ken Holman | Date | Re: [xsl] Traverse sub tree startin, Brandon Ibach | 
| Month |