xsl-list
[Top] [All Lists]

[xsl] numbering questions and answers entries

2007-04-16 04:03:50
Hello,
I am trying to transform a question and answer xml to html. My xml file looks like this:

<qandaset defaultlabel="qanda">
<title> questions and answers </title>
<qandadiv><title> Common Questions </title>
<qandaentry>
<question>
<par>
To be, or not to be?
</par>
</question>
<answer>
<par>
That is the question.
</par>
</answer>
<answer>
<par>
That is the question 2.
</par>
</answer>

</qandaentry>
</qandadiv>
<qandadiv><title> Deeper Questions </title>
<qandaentry>
<question>
<par>
Life?
</par>
</question>
<answer>
<par>
Never take it for granted.
</par>
</answer>
</qandaentry>
</qandadiv>
</qandaset>


<qandaset defaultlabel="number">
<title> Another qanda without qanddiv </title>
<qandaentry>
<question>
<par>
To be, or not to be?
</par>
</question>
<answer>
<par>
That is the question.
</par>
</answer>
<answer>
<par>
That is the question 2.
</par>
</answer>
</qandaentry>


<qandaentry>
<question>
<par>
Life?
</par>
</question>
<answer>
<par>
Never take it for granted.
</par>
</answer>
</qandaentry>
</qandaset>

I am trying to write a xslt stylesheet where i would label the questions and answers according to "defaultlabel" attribute, which values van be "qanda | number | none". I am having a problem when trying to display a number label. I am using xslt 1.0, My xsl stylesheet looks like this:


<xsl:template match="question" name="question">

<p><xsl:element name="a">
<xsl:attribute name="name">#<xsl:value-of select="normalize-space(.)"/></xsl:attribute>

<xsl:if test="ancestor::*[(_at_)defaultlabel]">
<xsl:choose>
<xsl:when test="ancestor::*[(_at_)defaultlabel='qanda']">
Q:<xsl:value-of select="par"/>
</xsl:when>

<xsl:when test="ancestor::*[(_at_)defaultlabel='number']">

<!--<xsl:number value="position()" format="1."/>
<xsl:value-of select="par"/>-->

</xsl:when>

<xsl:when test="ancestor::*[(_at_)defaultlabel='none']">
<xsl:value-of select="par"/>
</xsl:when>

</xsl:choose>
</xsl:if>
<!--<xsl:value-of select="par"/>-->

</xsl:element>
</p>
</xsl:template>

<xsl:template match="answer" name="answer">
<p>
<xsl:if test="ancestor::*[(_at_)defaultlabel]">
<xsl:choose>
<xsl:when test="ancestor::*[(_at_)defaultlabel='qanda']">
A:<xsl:value-of select="par"/>
</xsl:when>

<xsl:when test="ancestor::*[(_at_)defaultlabel='number']">
<xsl:value-of select="par"/>
</xsl:when>

<xsl:when test="ancestor::*[(_at_)defaultlabel='none']">
<xsl:value-of select="par"/>
</xsl:when>
</xsl:choose>
</xsl:if>
</p>
</xsl:template>




<xsl:template match="qandaset">
<xsl:for-each select="title">
<xsl:call-template name="titles"/>
<xsl:choose>
<xsl:when test="../qandadiv">
<xsl:for-each select="../qandadiv">
<p> <xsl:for-each select="title">
<xsl:call-template name="titles"/></xsl:for-each> </p>


<xsl:for-each select=".//qandaentry/question">
<xsl:element name="a">
<xsl:attribute name="href">#<xsl:value-of select="normalize-space(.)"/> </xsl:attribute>
<xsl:value-of select="par"/>

</xsl:element>
<br/>
</xsl:for-each>
<hr/>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="..//qandaentry/question">
<xsl:element name="a">
<xsl:attribute name="href">#<xsl:value-of select="normalize-space(.)"/> </xsl:attribute>
<xsl:value-of select="par"/>

</xsl:element>
<br/>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>

</xsl:for-each>
<xsl:for-each select=".//qandaentry">
<xsl:for-each select="question">
<xsl:call-template name="question"/>
</xsl:for-each>
<xsl:for-each select="answer">
<!-- <xsl:apply-templates/> -->
<xsl:call-template name="answer"/>
</xsl:for-each>
</xsl:for-each>

I did try several options but obviously i am doing something wrong.If somebody could give a solution,it would be a great help.

Thanks in advance,
Suida

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

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