Subject: Re: [xsl] Making an FAQ page from XML From: John Steel <john.steel@xxxxxxxxxxxxxxx> Date: Mon, 12 Feb 2007 21:35:17 +0000 |
John Steel wrote:Grrr!Kamal Bhatt wrote:Sorry, let me be clearer. local-name should be local-name()Don't make "*|@*" your first match. Make it your last. Instead, match on faqlist. Not entirely sure what are the extra content is, so I cannot really judge the right way of doing things. Try this:Thanks for your help - its almost there now. What I get is the right output, just duplicated.
<xsl:template match='faqlist'> <xsl:apply-templates select="*[local-name != 'faq']"/>
<xsl:apply-templates select="faq" mode="question"/> <xsl:apply-templates select="faq" mode="answer"/> </xsl:template>
<xsl:template match='*|@*'> <xsl:copy> <xsl:apply-templates select='node()|@*'/> </xsl:copy> </xsl:template>
1 Question 1
2 Question 2
...
1 Answer 1
2 Answer 2
...
1 Question 1
2 Question 2
...
1 Answer 1
2 Answer 2
...
This is the full stylesheet I used:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output media-type='text/html'/>
<xsl:template match='faqlist'> <xsl:apply-templates select="*[local-name != 'faq']"/> <xsl:apply-templates select="faq" mode="question"/> <xsl:apply-templates select="faq" mode="answer"/> </xsl:template>
<xsl:template match='faq' mode="question"> <tr> <td valign='top' width='24' class="mText" style="font-size: 11px"> <xsl:value-of select="count(preceding-sibling::*) + 1"/> </td> <td class="mText" style="font-size: 11px"> <a href='#1'> <xsl:value-of select='q'/> </a> </td> </tr> </xsl:template>
<xsl:template match='faq' mode="answer"> <tr> <td valign='top' width='24' class="mText" style="font-size: 11px"> <xsl:value-of select="count(preceding-sibling::*) + 1"/> </td> <td class="mText" style="font-size: 11px"> <a href="#1"> <xsl:value-of select='a'/> </a> </td> </tr> </xsl:template>
<xsl:template match='*|@*'> <xsl:copy> <xsl:apply-templates select='node()|@*'/> </xsl:copy> </xsl:template>
</xsl:stylesheet>
Did I make the changes you suggested correctly? I noticed taking out the line <xsl:apply-templates select="*[local-name != 'faq']"/> had no effect.
<xsl:template match='faqlist'> <xsl:apply-templates select="*[local-name() != 'faq']"/> <xsl:apply-templates select="faq" mode="question"/> <xsl:apply-templates select="faq" mode="answer"/> </xsl:template>
-- -------------------------- http://www.phonewebcam.com john.steel@xxxxxxxxxxxxxxx
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Making an FAQ page from X, Abel Braaksma | Thread | Re: [xsl] Making an FAQ page from X, Kamal Bhatt |
Re: [xsl] Making an FAQ page from X, Abel Braaksma | Date | Re: [xsl] Making an FAQ page from X, Kamal Bhatt |
Month |