Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XSLT Sequential Numbering

Reply
Thread Tools

XSLT Sequential Numbering

 
 
Liam
Guest
Posts: n/a
 
      07-17-2007
I am totally new to XML and XSLT, so I I have an XML file of:

<log>
<logvalue code="500" description="desc" >
<logvalue code="510" description="desc" >
<logvalue code="504" description="desc" >
<logvalue code="1" description="desc" >
<logvalue code="503" description="desc" >
<log>

I want to process it using XSLT transform. I want to generate a table
as HTML output with the first column as a sequential value of rows. I
am using :-

<xsl:if test='count(//log/logvalue [@code>=500]) &gt;
0'>
<xsl:if test='count(//log/logvalue
[@code&lt;=510]) &gt; 0'>
<table border="1">
<tr>
<th>Identifier</th>
<th>Code</th>
<th>Detail</th>
</tr>
<xsl:for-each select="//log/logvalue ">
<xsl:if test="@code>=500">
<xsl:if test="@code&lt;=510">
<tr>
<td style="width:10%">
<xsl:number/>
</td>

<td style="width:30%">
<xsl:value-of
select=@code/>
</td>

<td style="width:60%">
<<xsl:value-of
select="@description"/>
</td>
</tr>
</xsl:if>
</xsl:if>
</xsl:for-each>
</table>
</xsl:if>
</xsl:if>

Now the Identifier column should display a sequential value for each
row that is printed but when I use <xsl:number/> it is the position in
the list rather than the incremental value as it is printed.

Can anyone help here?

Thanks,Liam

 
Reply With Quote
 
 
 
 
Pavel Lepin
Guest
Posts: n/a
 
      07-17-2007

Liam <(E-Mail Removed)> wrote in
<(E-Mail Removed). com>:
> I am totally new to XML and XSLT, so I I have an XML file
> of:


I would recommend first reading some sort of tutorial then.

> <log>
> <logvalue code="500" description="desc" >
> <logvalue code="510" description="desc" >
> <logvalue code="504" description="desc" >
> <logvalue code="1" description="desc" >
> <logvalue code="503" description="desc" >
> <log>


Not well-formed.

[transformation snipped]

Not a complete transformation, not well-formed and
horrendously indented with no respect for the 78 chars
rule. You sure you want help?

> Now the Identifier column should display a sequential
> value for each row that is printed but when I use
> <xsl:number/> it is the position in the list rather than
> the incremental value as it is printed.


The typical solution would be something along the lines of:

<xsl:template match="log">
<result>
<xsl:apply-templates
select=
"
logvalue[@code >= 500 and @code &lt;= 510]
">
<xsl:sort select="@code"/>
</xsl:apply-templates>
</result>
</xsl:template>
<xsl:template match="logvalue">
<row>
<cell><xsl:value-of select="position()"/></cell>
<cell><xsl:value-of select="@code"/></cell>
<cell><xsl:value-of select="@description"/></cell>
</row>
</xsl:template>

Sometimes this is not feasible, and in that case the best
you can do is define a named template to calculate the row
position, using something like (untested):

count
(
../logvalue
[@code >= 500 and @code &lt;= 510]
[@code &lt; $current/@code]
)

Recursive processing might be an option as well, but this
path is fraught with peril.

--
....the pleasure of obedience is pretty thin compared with
the pleasure of hearing a rotten tomato hit someone in the
rear end. -- Garrison Keillor
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Nikon D800 sequential file numbering Rob Digital Photography 79 07-21-2012 01:18 AM
xslt - applying template to sequential group of nodes tuka XML 3 06-21-2007 11:01 PM
DOCBOOK/XSLT - Suppressing the automatic numbering Michael Doubez XML 1 01-27-2007 03:57 PM
sort and numbering - xslt pstachy XML 7 11-27-2006 11:15 PM
XSLT numbering by attribute James Merdan XML 1 09-24-2003 04:43 AM



Advertisments