473,414 Members | 1,598 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,414 software developers and data experts.

position() problem

Hi,
I've the following xml

<A>
<B>
<C>111</C>
<C>222</C>
<C>333</C>
</B>
<B>
<C>444</C>
<C>555</C>
<C>666</C>
</B>
</A>

The number of A is known but not the number of B. The number of B is
equal in each A.
The xml format is fixed and can't be changed.

I'd like to have the following result

1 111-444
2 222-555
3 333-666

For this I'm using the following script

<xsl:template match="/">
<xsl:for-each select="/A/B[1]/C">
<xsl:value-of select="position()"/> <xsl:value-of
select="/A/B[1]/C[position()]"/>-<xsl:value-of
select="/A/B[2]/C[position()]"/>
</xsl:for-each>
</xsl:template>

But the result given is

1 111-444
2 111-444
3 111-444

As if the position isn't working inside A[1]/B[position()]
Any idea?
Thanks for your help

Michel

Jan 17 '06 #1
1 1037


iw*******@hotmail.com wrote:

<A>
<B>
<C>111</C>
<C>222</C>
<C>333</C>
</B>
<B>
<C>444</C>
<C>555</C>
<C>666</C>
</B>
</A>

The number of A is known but not the number of B. The number of B is
equal in each A.
The xml format is fixed and can't be changed.

I'd like to have the following result

1 111-444
2 222-555
3 333-666


I am not sure why you could have several A elements (as A in your
example is the root element and there can be only one root element) but
the following stylesheet is one way to get the output

<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="text"/>

<xsl:template match="A">
<xsl:apply-templates select="B[1]" />
</xsl:template>

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

<xsl:template match="C">
<xsl:variable name="currentPos" select="position()" />
<xsl:value-of select="$currentPos" />
<xsl:text> </xsl:text>
<xsl:value-of select="." />
<xsl:apply-templates
select="../following-sibling::B/C[$currentPos]" mode="lineUp" />
<xsl:text> </xsl:text>
</xsl:template>

<xsl:template match="C" mode="lineUp">
<xsl:text>-</xsl:text>
<xsl:value-of select="." />
</xsl:template>

</xsl:stylesheet>

even if there are more B elements as long as the C elements match.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jan 17 '06 #2

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

Similar topics

1
by: Falc2199 | last post by:
Hi all, I am using the "Poistion" attribute to correctly align a column of images that I have on a table. The code looks like so.... <TD valign="top" class="listinglight" align="left"> <A...
5
by: CMAR | last post by:
I have been having a problem styling a page, which you can see live at my test site: Designer Page (http://home.ne.rr.com/thespar/) (Ignore the missing pictures, which have not been uploaded.)...
8
by: Jaime Rios | last post by:
Hi, I created a COM AddIn for Word that performs the functions that it needs to, but I needed to add the ability for the toolbar created by the COM AddIn to remember it's last position and...
3
by: akunamatata | last post by:
Hello everyone, I contact this discussiongroup because I encountered a little problem with XSL. Let me explain it: I have following file "position.xml": <?xml version="1.0"?>...
8
by: Edward | last post by:
I used to do this all the time in HTML-table layouting. How do I do this in CSS? -------------------------------------------------- <table width="400px"> <tr> <td bgcolor="beige">one line of...
5
by: Roderik | last post by:
Hi, My logo images are positioned some more to the right in IE6 than in FF1.5. I like them to be as shown in FF1.5. Does anyone have a clue, why they are positioned differently in IE? Problem...
2
by: petermichaux | last post by:
Hi, It seems like determining element position in a web page is a difficult task. In the position reporting source code I've looked at there are special fixes for at least some versions of...
2
by: agbee1 | last post by:
Hello: I've finally made the effort to ween myself from overly using tables and use CSS for my positioning. However, I am having a problem with my navigational menu properly aligning in Firefox,...
5
by: DL | last post by:
Hi, My research on this NG hasn't produced a satisfactory answer. Here's what I want to do: move two div (s) (each has an image tag within) to another location on the same page. // no...
12
Frinavale
by: Frinavale | last post by:
I think I'm trying to do something impossible. I have a <div> element with a overflow style set to "scroll". In other words my <div> element allows the user to scroll the content within it. ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.