xsl-list
[Top] [All Lists]

Re: A grouping question ?

2003-10-31 06:55:49
On Friday 31 Oct 2003 12:34, Emilio Gustavo Ormeño wrote:
Hi, I don't know if this is a grouping question, but given than I don't
know the way to solve it. I need your help. This is my problem:

I have a XML file such as:

<Content>
    <Paragraph bullet='false'>
        <Text txt='Hello World'/>
    </Paragraph>
    <Paragraph bullet='true'>
        <Text txt='First Bulleted Hello World'/>
    </Paragraph>
    <Paragraph bullet='true'>
        <Text txt='Second Bulleted Hello World'/>
    </Paragraph>
    <Paragraph bullet='false'>
        <Text txt='A normal line of text'/>
    </Paragraph>
    <Paragraph bullet='true'>
        <Text txt='Another bulleted line'/>
    </Paragraph>
    <Paragraph bullet='true'>
        <Text txt='A second bulleted line'/>
    </Paragraph>
</Content>

First, do you really need an element, 'Text' with an attribute, 'txt'? Why not 
just have <Text>...</Text>?


And I want an HTML output like the following:

<html>
    <p>Hello World</p>
    <ul>
        <li>First Bulleted Hello World</li>
        <li>Second Bulleted Hello World</li>
    </ul>
    <p>A normal line of text</p>
    <ul>
        <li>Another bulleted line</li>
        <li>A second bulleted line</li>
    </ul>
</html>


Does this mean that you want to format 'Paragraph' elements where 
@bullet='true' as <li>s and 'Paragraph's where @bullet='false' as <p>s?

<xsl:for-each select="para">
        <xsl:if test="@bullet = 'true' and 
preceding-sibling::[1]\(_at_)bullet='false'">
                <ul>
        </xsl:if>
        <xsl:choose>
                <xsl:when test="@bullet = 'true'">
                        <li><xsl:value-of select="text" /></li>
                </xsl:when>
                <xsl:otherwise>
                        <p><xsl:value-of select="text" /></p>
                </xsl:otherwise>
        </xsl:choose>
        <xsl:if test="@bullet = 'true' and 
following-sibling::[1]\(_at_)bullet='false'">
                </ul>
        </xsl:if>
</xsl:for-each>

(Not tested!)

Cheers,
Richard


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



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