Subject: RE: Axis specifers
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Mon, 15 Jan 2007 22:30:47 -0000
|
> Please let me know where I am going wrong.
I started before, but it got too complicated, so I gave up. I don't normally
answer XSL-FO questions, but in fact your problem seems to have nothing to
do with XSL-FO, and it would be useful to simplify it by removing a lot of
the noise.
>
> Sample XML:
>
> <list>
> <note><para>This is the first note.</para></note>
> <note><para>This is the second note. </para></note>
> <text><para>This is some text. </para></text>
> </list>
> My desired output is:
>
>
> NOTE: This is the first note.
> NOTE: This is the second note.
> 1. This is some text.
This seems to be simply achievable as:
<xsl:template match="list">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="note">
<xxx>NOTE:</xxx>
<yyy><xsl:apply-templates select="para"/></yyy>
</xsl:template>
<xsl:template match="text">
<xxx><xsl:number/></xxx>
<yyy><xsl:apply-templates select="para"/></yyy>
</xsl:template>
With xxx and yyy replaced by suitable XSL-FO elements.
Now to comment on your code.
>
> XSLT:
> <xsl:template match="note">
> <xsl:choose>
> <xsl:when test="parent::list and
> position()=1"> </xsl:when>
Every note in your input has a parent::list so I don't understand why you
are testing this.
The way a note is rendered doesn't depend on its position, so I don't
understand why you are testing this either.
>
> <!-- This is the template for list-->
>
> <xsl:template match="list">
> <xsl:if test="child::note">
> <xsl:apply-templates select="note" mode="list"/> </xsl:if>
> </xsl:template>
The xsl:if serves no useful purpose, because if the list has no note
children then the apply-templates will do nothing.
Why aren't you outputting the text child here, since your specimen output
indicates that you want it output?
>
> <xsl:template match="note" mode="list">
Why have you got two different modes for processing a note?
> <xsl:template match="note/para" mode="list">
I can't see when this is supposed to be invoked.
> Can anyone help me resolve this issue? How can I tell the
> processor that after the first position of "note" check if
> there is another "note" element and if it is, then that
> should also be displayed above the text element on the
> output, following the first note element? So irrespective of
> the number of "note" elements inside the <list> element, they
> shoudl always be displayed above the <text> element as shown
> in the desired output. Please give me any ideas and suggestions.
>
The above sounds like a very complicated way of saying "display all the
notes, then display the text". Where is the difficulty?
(I'm fully expecting you to come back with the usual follow-up that says
sorry, I oversimplified my example...)
Michael Kay
http://www.saxonica.com/
|