xsl-list
[Top] [All Lists]

Re: [xsl] Axis specifers

2007-01-16 09:02:31
Hello:

I am sorry for reposting this issue, but it errored out when I sent it
and so since it didnt come up on the list for a long time, I thought
the message did not go thru and reposted it.

Thank you Michael for your response.

I will try to answer your questions to clarify:

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.

The intention behind this was this. If a 'note' element appeared
immediately after the list element, then I needed to display it before
the text element. A note element can appear anywhere inside the list
element like this for example:

<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>
<note><para>This note is after the text. </para></note>
</list>

So, only if the <note> element appeared before the text, it will have
to be displayed before the text element like this:

NOTE: This is the first note.
NOTE: This is the second note.
1. This is some text.

If the note element appeared after text, then it is displayed after
the text. This is the reason for the statement " <xsl:if
test="child::note">
<xsl:apply-templates select="note" mode="list"/> </xsl:if>"

Here, I am checking if the <note> element is an immediate child of
list, and if it is I display it before the text using the "mode=list"
template. Otherwise, it will be displayed after <text> using the
regular "note" template.

The problem I am facing is, this logic works when <note> is the first
child of list. But if there is another note following <list> it fails
since I was checking for <position()=1>

This is what I want to achieve in my XSLT. Does this make things
clear? Please do let me know.

On 1/15/07, Michael Kay <mike(_at_)saxonica(_dot_)com> wrote:
> 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/


--~------------------------------------------------------------------
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>
--~--



--~------------------------------------------------------------------
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>
--~--