473,405 Members | 2,210 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,405 software developers and data experts.

Recursion of tags in one tag

Hello everybody,

I have a question about xml / xsl(t).

I need to transform a following kind of xml to editable file (format
does not matter).

The xml file look like this:

<...> Root
<tag>
<subtag1>.....</subtag1>
<subtag2>.....</subtag2>
....
....
<subtag1>.....</subtag1>
<subtag2>.....</subtag2>
</tag>
</...> End Root

Subtag1 & Subtag2 can repeat themselves n-times.
I know that this is xml is wellformed but not wellstructured.

The ideal solution should be:

<...> Root
<tag>
<detail>
<subtag1>.....</subtag1>
<subtag2>.....</subtag2>
</detail>
<detail>
<subtag1>.....</subtag1>
<subtag2>.....</subtag2>
</detail>
</tag>
</...> End Root

If the xml should like this (in the ideal case) I could get the
conversion to work in no time.

Any suggestions how I could write a correct xsl(t) for the first
example???

Thank you
Jul 20 '05 #1
2 1354
Tempore 15:25:40, die Thursday 10 February 2005 AD, hinc in foro {comp.text.xml} scripsit Cedric Vonck <va**********@ping.be>:

Subtag1 & Subtag2 can repeat themselves n-times.
I know that this is xml is wellformed but not wellstructured.

The ideal solution should be:

<...> Root
<tag>
<detail>
<subtag1>.....</subtag1>
<subtag2>.....</subtag2>
</detail>
<detail>
<subtag1>.....</subtag1>
<subtag2>.....</subtag2>
</detail>
</tag>
</...> End Root

If the xml should like this (in the ideal case) I could get the
conversion to work in no time.

Any suggestions how I could write a correct xsl(t) for the first
example???

Hi,

I'm not really sure if this is really what you asked for, but here's an xslt that converts the first document into the second:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>

<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>

<xsl:template match="*[subtag1]">
<xsl:copy>
<xsl:apply-templates select="node()[not(self::subtag2)] | @*"/>
</xsl:copy>
</xsl:template>

<xsl:template match="subtag1">
<details>
<xsl:copy-of select=". | following-sibling::subtag2[1]"/>
</details>
</xsl:template>

</xsl:stylesheet>
regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Vincit omnia simplicitas
Keep it simple
Jul 20 '05 #2
> <xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>

<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>

<xsl:template match="*[subtag1]">
<xsl:copy>
<xsl:apply-templates select="node()[not(self::subtag2)] | @*"/>
</xsl:copy>
</xsl:template>

<xsl:template match="subtag1">
<details>
<xsl:copy-of select=". | following-sibling::subtag2[1]"/>
</details>
</xsl:template>

</xsl:stylesheet>
regards,


Thank you for your answer, but I should have made my post more
clearer.
The second example with the (<detail>) tag is no problem for me.
It is the first one that poses problems.

So if possible, could anyone explain to me how I have to write a
decent xsl(t) for it??

Thx
Jul 20 '05 #3

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

Similar topics

0
by: Bill Loren | last post by:
Hi ppl, Trying to substitute some html tags within a big html file using RE ended up with the "RuntimeError: maximum recursion limit exceeded" message. Any idea why that might happen and how...
5
by: Peri | last post by:
I'm trying to create Python parser/interpreter using ANTLR. Reading grammar from language refference I found: or_expr::= xor_expr | or_expr "|" xor_expr For me it looks like infinite recursion....
12
by: da Vinci | last post by:
Greetings. I want to get everyone's opinion on the use of recursion. We covered it in class tonight and I want a good solid answer from people in the "know" on how well recursion is accepted...
43
by: Lorenzo Villari | last post by:
I've tried to transform this into a not recursive version but without luck... #include <stdio.h> void countdown(int p) { int x;
75
by: Sathyaish | last post by:
Can every problem that has an iterative solution also be expressed in terms of a recursive solution? I tried one example, and am in the process of trying out more examples, increasing their...
18
by: MTD | last post by:
Hello all, I've been messing about for fun creating a trial division factorizing function and I'm naturally interested in optimising it as much as possible. I've been told that iteration in...
13
by: robert | last post by:
My code does recursion loops through a couple of functions. Due to problematic I/O input this leads sometimes to "endless" recursions and after expensive I/O to the Python recursion exception. What...
14
RMWChaos
by: RMWChaos | last post by:
Firebug is reporting "too much recursion" when I attempt to create a child element in a parent that doesn't exist yet. The script should automatically create the missing parent before going on to...
20
by: athar.mirchi | last post by:
..plz define it.
35
by: Muzammil | last post by:
int harmonic(int n) { if (n=1) { return 1; } else { return harmonic(n-1)+1/n; } } can any help me ??
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.