473,325 Members | 2,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Numbering Nodes

Hi,

I need to number a set of PARA nodes as outlined below:

<?xml version="1.0" encoding="utf-8"?>
<DESCRIPT>
<PARA0>
<PARA>Paragraph 1</PARA>
</PARA0>
<PARA0>
<PARA>Paragraph 2</PARA>
<SPECPARA>
<CAUTION>
<PARA>Special Caution paragraph 1</PARA>
</CAUTION>
<PARA>Paragraph 3</PARA>
</SPECPARA>
<PARA>Paragraph 4</PARA>
</PARA0>
<DESCRIPT>
<!-- Desired Output:

1. Paragraph 1

2. Paragraph 2

-- CAUTION --
Special Caution paragraph 1

3. Paragraph 3

Paragraph 4
I have created the following XSLT to do this, but it doesn't quite
work the way I'd like:

<!-- SNIP -->
<xsl:template match="PARA">
<xsl:choose>
<xsl:when test="(name(../..) = 'PARA0' and name(..) = 'SPECPARA')
or name(..) = 'PARA0'">
<table style="width:100%;border:0;" class="para0">
<tr style="vertical-align:top;">
<td style="width:12mm;font-weight:bold;">
<xsl:if test="self::node() [generate-id() =
generate-id(parent::node()/child::PARA [position() = 1])]">
<xsl:number format="1. "
count="PARA0 [PARA != '' or SPECPARA/PARA = '']"
level="single" />
</xsl:if>
</td>
<td class="para">
<a>
<xsl:attribute name="name">
<xsl:value-of select="@ID"/>
</xsl:attribute>
<xsl:apply-templates />
</a>
</td>
</tr>
</table>
</xsl:when>
<!-- SNIP -->

This produces the following results:
1. Paragraph 1

2. Paragraph 2

2. Paragraph 3

Paragraph 4

Any help on how to number Paragraph 3 as 3 instead of 2 would be
greatly appreciated.

Regards
Dwayne
Jul 20 '05 #1
2 1602
Hi,

dw**************@hotmail.com (Dwayne Wilkinson) writes:
I need to number a set of PARA nodes as outlined below:

<?xml version="1.0" encoding="utf-8"?>
<DESCRIPT>
<PARA0>
<PARA>Paragraph 1</PARA>
</PARA0>
<PARA0>
<PARA>Paragraph 2</PARA>
<SPECPARA>
<CAUTION>
<PARA>Special Caution paragraph 1</PARA>
</CAUTION>
<PARA>Paragraph 3</PARA>
</SPECPARA>
<PARA>Paragraph 4</PARA>
</PARA0>
<DESCRIPT>
<!-- Desired Output:

1. Paragraph 1

2. Paragraph 2

-- CAUTION --
Special Caution paragraph 1

3. Paragraph 3

Paragraph 4


If you change your xsl:number element to the following it will do the
job, if I understand correctly (note use of value attribute rather
than count).

<xsl:number format="1. "
value="1+count(preceding::PARA[not(name(../..)='SPECPARA')])"
level="single" />

It does seem strange markup though - let's see if I understand in
words what you want:

You want to output PARA elements that are the children of PARA0 or
the children of SPECPARA and grandchildren of PARA0.

You also want to handle the SPECPARA/CAUTION/PARA element
separately.

You want to number consecutively PARA elements that are the first
PARA children of their parents whether that parent is PARA0 or
SPECPARA
If I've understood correctly the following should help. I've
re-organised it what you might call a more XSLT way which simplifies
some of the logic, and easily allows you to handle the CAUTION case.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output indent="yes"/>

<xsl:template match="/">
<xsl:apply-templates select="//PARA0"/>
</xsl:template>

<xsl:template match="PARA0">
<xsl:apply-templates select="PARA | SPECPARA"/>
</xsl:template>

<xsl:template match="SPECPARA">
<h2>Caution!!!</h2>
<xsl:value-of select="CAUTION/PARA"/>
<xsl:apply-templates select="PARA"/>
</xsl:template>

<xsl:template match="PARA">
<table style="width:100%;border:0;" class="para0">
<tr style="vertical-align:top;">
<td style="width:12mm;font-weight:bold;">
<xsl:if test="position() = 1">
<xsl:number format="1. "
value="1+count(preceding::PARA[not(name(../..)='SPECPARA')])"
level="single" />
</xsl:if>
</td>
<td class="para">
<a>
<xsl:attribute name="name">
<xsl:value-of select="@ID"/>
</xsl:attribute>
<xsl:apply-templates />
</a>
</td>
</tr>
</table>
</xsl:template>

</xsl:stylesheet>
--
Ben Edgington
Mail to the address above is discarded.
Mail to ben at that address might be read.
http://www.edginet.org/
Jul 20 '05 #2
Ben Edgington <us****@edginet.org> wrote in message news:<87************@edginet.org>...

If you change your xsl:number element to the following it will do the
job, if I understand correctly (note use of value attribute rather
than count).

<xsl:number format="1. "
value="1+count(preceding::PARA[not(name(../..)='SPECPARA')])"
level="single" />

It does seem strange markup though - let's see if I understand in
words what you want:

You want to output PARA elements that are the children of PARA0 or
the children of SPECPARA and grandchildren of PARA0.

You also want to handle the SPECPARA/CAUTION/PARA element
separately.

You want to number consecutively PARA elements that are the first
PARA children of their parents whether that parent is PARA0 or
SPECPARA
If I've understood correctly the following should help. I've
re-organised it what you might call a more XSLT way which simplifies
some of the logic, and easily allows you to handle the CAUTION case.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output indent="yes"/>

<xsl:template match="/">
<xsl:apply-templates select="//PARA0"/>
</xsl:template>

<xsl:template match="PARA0">
<xsl:apply-templates select="PARA | SPECPARA"/>
</xsl:template>

<xsl:template match="SPECPARA">
<h2>Caution!!!</h2>
<xsl:value-of select="CAUTION/PARA"/>
<xsl:apply-templates select="PARA"/>
</xsl:template>

<xsl:template match="PARA">
<table style="width:100%;border:0;" class="para0">
<tr style="vertical-align:top;">
<td style="width:12mm;font-weight:bold;">
<xsl:if test="position() = 1">
<xsl:number format="1. "
value="1+count(preceding::PARA[not(name(../..)='SPECPARA')])"
level="single" />
</xsl:if>
</td>
<td class="para">
<a>
<xsl:attribute name="name">
<xsl:value-of select="@ID"/>
</xsl:attribute>
<xsl:apply-templates />
</a>
</td>
</tr>
</table>
</xsl:template>

</xsl:stylesheet>


Hi Ben,

Thanks for the reply, yes it sounds like you understood the problem
correctly, the XSLT is meant to create online technical manuals from a
couple of different Defence SGML standards (converted to XML).

I'll give it a try tomorrow to see how it goes.

Thanks for the excellent and detailed response.

Regards
Dwayne
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Andy Glew | last post by:
I have long looked for (and occasionally posted questions to groups such as this about) a tool that can take a group of HTML pages (nowadays XHTML, or XML) and produce a nicely formatted...
10
by: Mike Dickens | last post by:
hi, suppose i have: <a> <b i="Y" j="aaaa"/> <c i="N" j="bbbb"/> <d i="Y" j="cccc"/> <e i="N" j="dddd"/> <f i="N" j="eeee"/> <g i="Y" j="ffff"/>
6
by: Stanimir Stamenkov | last post by:
So if the 'type' attribute of the OL element is deprecated and authors should rely only on stylesheets how one could use a reference (as clear text) in the content to a particular list element? ...
6
by: Christian Roth | last post by:
Hello, how do I offset the numbering of a list in XHTML Strict (+CSS) in current browsers? What I want is something like: 5. Item a 6. Item b 7. Item c
5
by: Charles McCaffery | last post by:
I have written a database with auto-numbering and now wish to remove alkl of my test data and set the auto-numbering back to one. How do I do this please? Charles McCaffery.
1
by: Wayne Aprato | last post by:
I have a report that shows the results of a query. One of the fields is an autonumber field from the query which shows for instance: 120, 121 , 122 for 3 records. Is there a way to have another...
2
by: Wayne Aprato | last post by:
I posted this yesterday and it seems like a moderator has thrown it in another thread. This is a totally different question to the one asked in that thread, so I'm posting it again. It is not a...
7
by: pstachy | last post by:
Hi all, I'm having problem with XSLT transformation concerned with sort and numberings at a time. I wish to have my registries sorted alfabetically and would like them to have numberings at a...
8
by: Wayne | last post by:
When I couldn't find it on-line by Googling, I spent all last night working it out. And it works, Yea! All you do is mark the PRE sections you want numbered with a "marker" style like this: ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.