Re: [xsl] Dynamic numbering of lists in xslt

Subject: Re: [xsl] Dynamic numbering of lists in xslt
From: xslt.new <xslt.new@xxxxxxxxx>
Date: Wed, 10 Jan 2007 15:37:09 -0600
ok I think i spoke too fast. I forogot another condition. What if
there is a <travel1> tag without any condition in it, but I still want
to count it in sequence with the ones which satisfy the condition?

That is:
<travel1>
<location
<place>NY<place>
<time>EST</time>
</location>
  <travel2>
<location
<place>CaL<place>
<time>PST</time>
</location>
</travel2>
</travel1>

<travel1>
<location
<place>Chi<place>
<time>CST</time>

</location>
</travel1>
<travel1>
<location
<place>NY<place>
<time>EST</time>

</location>
</travel1>
<!-- This is the travel1 without any condition that needs to be counted-->
<travel1>
<text>Some text</text>
</travel1>

I used <xsl:number from="/" count="travel1[location/time=$time and
location/place=$place]"/>

This counts only those travel1 tags which satisfy the conditions and
gives an output like this:

1. NY, EST
2. NY, EST

Now since I have another <travel1> tag without any conditions around
it, I want that to be counted as #3 and not as #4. But now, i get

1. NY, EST
2. NY, EST
4.Some text

Instead I want to count this sequentially with the <travel1> tags
which have the place and time conditions satisfied.

So I would want:
1. NY, EST
2. NY, EST
3.Some text

I tried:

<xsl:template match="travel1">

<xsl:choose>

<xsl:when test=".//location">
<xsl:if test=".//location/place=$place and .//location/time=$time">
<fo:list-block space-before="6pt" space-before.conditionality="retain">
      <fo:list-item>
              <fo:list-item-label end-indent="label-end()">
                      <fo:block>
                              <xsl:number format="1"/>
                      </fo:block>
              </fo:list-item-label>
              <fo:list-item-body start-indent="body-start()" end-indent="0pt">
                      <fo:block>
                              <xsl:apply-templates/>
                      </fo:block>
              </fo:list-item-body>
      </fo:list-item>
</fo:list-block>
</xsl:if>
</xsl:when>
<!-- This is for the <travel tags without any cnditions-->
without any condition in it, but I still want to count it in sequence
with the ones which satisfy the condition?

That is:
<travel1>
<location
<place>NY<place>
<time>EST</time>
</location>
  <travel2>
<location
<place>CaL<place>
<time>PST</time>
</location>
</travel2>
</travel1>

<travel1>
<location
<place>Chi<place>
<time>CST</time>

</location>
</travel1>
<travel1>
<location
<place>NY<place>
<time>EST</time>

</location>
</travel1>
<!-- This is the travel1 without any condition that needs to be counted-->
<travel1>
<text>Some text</text>
</travel1>

I used <xsl:number from="/" count="travel1[location/time=$time and
location/place=$place]"/>

This counts only those travel1 tags which satisfy the conditions and
gives an output like this:

1. NY, EST
2. NY, EST

Now since I have another <travel1> tag without any conditions around
it, I want that to be counted as #3 and not as #4. But now, i get

1. NY, EST
2. NY, EST
4.Some text

Instead I want to count this sequentially with the <travel1> tags
which have the place and time conditions satisfied.

So I would want:
1. NY, EST
2. NY, EST
3.Some text

I tried:

<xsl:template match="travel1">

<xsl:choose>

<xsl:when test=".//location">
<xsl:if test=".//location/place=$place and .//location/time=$time">
<fo:list-block space-before="6pt" space-before.conditionality="retain">
      <fo:list-item>
              <fo:list-item-label end-indent="label-end()">
                      <fo:block>
                <xsl:number from="/"
count="travel1[location/time=$time and location/place=$place]"
format="1"/>
                      </fo:block>
              </fo:list-item-label>
              <fo:list-item-body start-indent="body-start()" end-indent="0pt">
                      <fo:block>
                              <xsl:apply-templates/>
                      </fo:block>
              </fo:list-item-body>
      </fo:list-item>
</fo:list-block>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<fo:list-block space-before="6pt" space-before.conditionality="retain">
      <fo:list-item>
              <fo:list-item-label end-indent="label-end()">
                      <fo:block>
                <xsl:number from="/" count="travel1" format="1"/>
                      </fo:block>
              </fo:list-item-label>
              <fo:list-item-body start-indent="body-start()" end-indent="0pt">
                      <fo:block>
                              <xsl:apply-templates/>
                      </fo:block>
              </fo:list-item-body>
      </fo:list-item>
</fo:list-block>

</xsl:otherwise>
</xsl:choose>
</xsl:template>




On 1/10/07, David Carlisle <davidc@xxxxxxxxx> wrote:


> I need to use a numberd list but this time using XSLFO and not XSLT.

what do you mean? XSLFO allows the specification of typesetting
properties but has no capability to do any programming of any sort.
The rest of tyour posting consists of some example XSLT stylesheets
(the XSLT happens to use XSLFO literal result elements, but that is
irrelevant to both the XSLt engine and your problem)

as far as i can tell you want to count travel nodes which have a
location child that matches your params, so use something like

<xsl:number from="/" count="travel1[location/time=$time and location/place=$place]"/>


Do you really want to make a list with one item for each travel element, why not make a single list outside the code that you have shown and then just generate <fo:list-item> in the travel1 template.


> Please let me know if any of this is achievable in XSLFO using > renderx.

Your question has nothing to do with xslfo, it's about how to generate
the right number using xslt.

David

Current Thread