[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Numbering and adding commas

Subject: RE: Numbering and adding commas
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 10 Mar 2006 23:34:30 -0000
adding commas to my list
Your code is:

<xsl:for-each select="answer">
    <xsl:if test="position() != last()">
      <xsl:apply-templates select="."/>, <xsl:text/>

which means

for each answer, if it is not the last answer, process the answer and then
output a comma.

Clearly you want

for each answer, process the answer, and if it is not the last, output a

Just move the apply-templates out of the conditional.

Michael Kay

> -----Original Message-----
> From: Terry Ofner [mailto:tofner@xxxxxxxxxxx]
> Sent: 10 March 2006 23:05
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Numbering and adding commas
> Greetings,
> I have been hitting my head against this problem for several
> days. I was
> determined to figure it out on my own with the various resources now
> available. But no love.
> I have questions with multiple answer tagged, such as this one:
>   <topic>Finding Nouns</topic>
> <item> 1. At one <answer>time</answer> <answer>dinosaurs</answer> were
> <answer>rulers</answer> of the <answer>earth</answer>.</item>
> Some items have only one answer tagged:
> <item> 2. <answer>Most</answer> of the flags before then were actually
> poles</item>
> I am trying to list the answers for each item after the
> number. But then I
> am also trying to add a comma after all but the last item in
> the list, like
> this:
> 1.    time, dinosaurs, rulers, earth
> Here is relevant part of my stylesheet:
>   <xsl:template match="item">
>     <xsl:text>&#10;</xsl:text>
>     <xsl:text>&#9;</xsl:text>
>     <xsl:number count="item" level="any" from="topic"
> format="1.&#9;"/>
>     <xsl:for-each select="answer | ansus | ansdus | embedded |
> attribute::answer">
>        <xsl:if test="position() != last()">
>       <xsl:apply-templates select="."/>, <xsl:text/>
>     </xsl:if>
>     </xsl:for-each>
>   </xsl:template>
> This current snippet produces the output below, in which the
> last answer has
> been cut completely.
> Finding Nouns
>     1.    time, dinosaurs, rulers,
> I love reading the list. Please excuse my newbie malformed code.
> Terry

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.