[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Hello,
I am trying to transform a question and answer xml to html. My xml file looks like this:
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:when test="ancestor::*[@defaultlabel='number']">
</xsl:when>
<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"/>
I did try several options but obviously i am doing something wrong.If somebody could give a solution,it would be a great help.
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
[xsl] numbering questions and answers entries
Subject: [xsl] numbering questions and answers entries From: "marvi vokopola" <vmarvi@xxxxxxxxxxx> Date: Mon, 16 Apr 2007 13:02:53 +0200 |
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::*[@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: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/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Identifying Namespace Dec, Abel Braaksma | Thread | Re: [xsl] numbering questions and a, Eric Bréchemier |
Re: [xsl] How to move processing in, J. S. Rawat | Date | RE: [xsl] check the type of the $pa, Michael Kay |
Month |