[Home] [By Thread] [By Date] [Recent Entries]
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>
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::*[@defaultlabel]"> <xsl:choose> <xsl:when test="ancestor::*[@defaultlabel='qanda']"> Q:<xsl:value-of select="par"/> </xsl:when> <xsl:when test="ancestor::*[@defaultlabel='number']"> <!--<xsl:number value="position()" format="1."/> <xsl:value-of select="par"/>--> </xsl:when> <xsl:when test="ancestor::*[@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::*[@defaultlabel]"> <xsl:choose> <xsl:when test="ancestor::*[@defaultlabel='qanda']"> A:<xsl:value-of select="par"/> </xsl:when> <xsl:when test="ancestor::*[@defaultlabel='number']"> <xsl:value-of select="par"/> </xsl:when> <xsl:when test="ancestor::*[@defaultlabel='none']"> <xsl:value-of select="par"/> </xsl:when> </xsl:choose> </xsl:if> </p> </xsl:template>
<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/
|

Cart



