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

Help needed with transition

Hi

Can anyone help me with the following transition? My problem is how to create
a fieldset each time I run into a heading and then include the following text
elements within the fieldset.

<?xml version="1.0" encoding="ISO-8859-1"?>
<field>
<heading>First heading</heading>
</field>
<field>
<text>Lorem</text>
</field>
<field>
<text>Ipsum</text>
</field>
<field>
<heading>Second heading</heading>
</field>
<field>
<text>Dolor</text>
</field>
<field>
<text>Sit</text>
</field>
<field>
<heading>Third heading</heading>
</field>
<field>
<text>Amet</text>
</field>

To

<fieldset>
<legend>First heading</legend>
<p>Lorem</p>
<p>Ipsum</p>
</fieldset>
<fieldset>
<legend>Second heading</legend>
<p>Dolor</p>
<p>Sit</p>
</fieldset>
<fieldset>
<legend>Third heading</legend>
<p>Amet</p>
</fieldset>
Nov 18 '08 #1
2 1316
I'm getting closer but still no cigar :-(

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"<xsl:template match="/">
<xsl:apply-templates select="//heading" />
</xsl:template>
<xsl:template match="heading">
<fieldset>
<legend>
<xsl:value-of select="."/>
</legend>
<!-- Only text elements following above heading -->
<xsl:apply-templates select="//text" />
</fieldset>
</xsl:template>
<xsl:template match="text">
<p>
<xsl:value-of select="."/>
</p>
</xsl:template>
</xsl:stylesheet>

Where my comment is in the XSLT above I need help. I've looked at
following-sibling which could be what I need but I can't figure out how...
anyone?

On 18-11-2008 22:40:30, "Hvid Hat" wrote:
Hi

Can anyone help me with the following transition? My problem is how to
create a fieldset each time I run into a heading and then include the
following text elements within the fieldset.

<?xml version="1.0" encoding="ISO-8859-1"?>
<field>
<heading>First heading</heading>
</field>
<field>
<text>Lorem</text>
</field>
<field>
<text>Ipsum</text>
</field>
<field>
<heading>Second heading</heading>
</field>
<field>
<text>Dolor</text>
</field>
<field>
<text>Sit</text>
</field>
<field>
<heading>Third heading</heading>
</field>
<field>
<text>Amet</text>
</field>

To

<fieldset>
<legend>First heading</legend>
<p>Lorem</p>
<p>Ipsum</p>
</fieldset>
<fieldset>
<legend>Second heading</legend>
<p>Dolor</p>
<p>Sit</p>
</fieldset>
<fieldset>
<legend>Third heading</legend>
<p>Amet</p>
</fieldset>
Nov 18 '08 #2
David has given both a 2.0 and a 1.0 solution. I wouldn't write
anything different for what David wrote for XSLT 2.0.

But here's a slightly different 1.0 solution,

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

<xsl:output method="xml" indent="yes" />

<xsl:template match="x">
<result>
<xsl:apply-templates select="field[heading]" mode="a" />
</result>
</xsl:template>

<xsl:template match="field" mode="a">
<fieldset>
<legend><xsl:value-of select="heading" /></legend>
<xsl:apply-templates select="following-sibling::field[1][text]"
mode="b" />
</fieldset>
</xsl:template>

<xsl:template match="field" mode="b">
<p><xsl:value-of select="text" /></p>
<xsl:apply-templates select="following-sibling::field[1][text]"
mode="b" />
</xsl:template>

</xsl:stylesheet>

this is popularly known as the sibling recursion technique.

Cheers,
Mukul

On Nov 19, 2:40*am, "Hvid Hat" <hvid....@please-no-mail.thxwrote:
Hi

Can anyone help me with the following transition? My problem is how to create
a fieldset each time I run into a heading and then include the following text
elements within the fieldset.

<?xml version="1.0" encoding="ISO-8859-1"?>
<field>
* <heading>First heading</heading>
</field>
<field>
* <text>Lorem</text>
</field>
<field>
* <text>Ipsum</text>
</field>
<field>
* <heading>Second heading</heading>
</field>
<field>
* <text>Dolor</text>
</field>
<field>
* <text>Sit</text>
</field>
<field>
* <heading>Third heading</heading>
</field>
<field>
* <text>Amet</text>
</field>

To

<fieldset>
* <legend>First heading</legend>
* <p>Lorem</p>
* <p>Ipsum</p>
</fieldset>
<fieldset>
* <legend>Second heading</legend>
* <p>Dolor</p>
* <p>Sit</p>
</fieldset>
<fieldset>
* <legend>Third heading</legend>
* <p>Amet</p>
</fieldset>
Nov 19 '08 #3

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

Similar topics

1
by: Alex Pavluck | last post by:
Hello. I am trying to teach myself PYTHON because I am interested in programming. I use SAS all day and I really like the way you can highlight code and submit just that section or submit the...
3
by: Richard A. DeVenezia | last post by:
I hope this is the end of my present 'discovery' phase. I've learned alot about JavaScript in a short time and my head hurts. The following is what came out of all my questions and all the...
1
by: WJA | last post by:
I have a sized form with a custom menu bar. Using a command button on this form, I'm opening a report which has a different custom menu bar. When I close the report, the transition of the menu bar...
3
by: ATS | last post by:
I'm trying to set up a slide show on a web page using Javascript. Here is the code I have so far: <script language="javascript"> alert("**in test area 1"); slides = new Array(); slides =...
2
by: Emil | last post by:
Hi, if you open the link below and click on "Show Me" and then "Toggle Transition" Button you will see a wonderfull fade in / fade out transition of 2 pictures. ...
3
by: Willing 2 Learn | last post by:
Hey, I'm trying to teach myself C++ and I came across 3 problems. I understand the concept of FSA but getting the C++ code to do it as become an issue. Only thing is im clueless as to how to do...
9
by: takeiteasy | last post by:
Hello everyone, I've got a question about programming by using Java applet and the question is : Design a web page containing an applet that simply switches from one image to the next with some...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
4
by: scoobydoo9749 | last post by:
So I was on here the other day looking for help with the getElementByName method and recieved excellent help quickly. (Thankyou GITS) Now, I'm looking for some help with making some dynamic content...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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.