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

Problem with XSL tranformation: nested elements

Max
Hi!
I have a problem with an XSL transformation. This is the XML file to
transform: there's an "article" with one element of type "text". There
are two nested elements of type "image" and "text":

<article>

<element type="text ">
<![CDATA[Some introductory text]]>

<element name="photo" type="image" ext="jpg"/>

<element type="text ">
<![CDATA[Text related to the image]]>
</element>

</element>

</article>

My goal is to print:

Some introductory text
<img src="photo.jpg" />.
Text related to the image.

This is the XSL:

<xsl:template match="/">

<xsl:apply-templates select="/article/element[@type = 'text]"/>

<xsl:apply-templates select="article/element/element[@type =
'image']"/>

</xsl:template>

<xsl:template match="article/element[@type = 'text']">

<xsl:value-of select="." />

</xsl:template>

<xsl:template match="/article/element/element[@type = 'image']">

<img src="{@name}.{@ext}" />.
<xsl:apply-templates select="../element[@type = 'text-body']"/>

</xsl:template>

The problem is that the XSL prints the first and the second text
together. This is the result of the XSL:

Some introductory text. Text related to the image.
<img src="photo.jpg" />.
Text related to the image.

How can I solve the problem? Thanks!

Bye, Max

Aug 19 '07 #1
1 2749
Max wrote:
I have a problem with an XSL transformation. This is the XML file to
transform: there's an "article" with one element of type "text". There
are two nested elements of type "image" and "text":

<article>

<element type="text ">
<![CDATA[Some introductory text]]>

<element name="photo" type="image" ext="jpg"/>

<element type="text ">
<![CDATA[Text related to the image]]>
</element>

</element>

</article>

My goal is to print:

Some introductory text
<img src="photo.jpg" />.
Text related to the image.
You need just one template

<xsl:template match="element[@type = 'image']">
<img src="{@name}.{ext}" />
<xsl:apply-templates />
</xsl:template>

for the rest the default templates will kick in and do what you want
(minus some white space issues).

<xsl:template match="article/element[@type = 'text']">

<xsl:value-of select="." />

</xsl:template>
The string value of an element is the text contents of all children and
descendants.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 19 '07 #2

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

Similar topics

5
by: Clifford W. Racz | last post by:
Has anyone solved the issue of translating lists in Word 2003 (WordML) into xHTML? I have been trying to get the nested table code for my XSLT to work for a while now, with no way to get the...
29
by: Joseph Haig | last post by:
I am trying to use descriptive lists, <DL>, as shown in <http://www.maths.man.ac.uk/~jhaig/tmp/test.html> with a style sheet at <http://www.maths.man.ac.uk/~jhaig/tmp/default-2.css>. With Mozilla...
2
by: Felipe Gasper | last post by:
I'm trying to make some "sub-cells" in an HTML table and to control their positioning and content presentation via CSS. In the table at the following URL: ...
9
by: Dustin | last post by:
Here's what I am trying to do: (Names represent CSS classes.) I want to create a photo gallery. I want the entire gallery to be surrounded by a box named PhotoGallery. I want a fluid placement...
5
by: javaguy | last post by:
I have a data entry web application that is formatted heavily with tables. Having learned a bit of CSS, I'm hoping to rewrite this using <div> tags. But I have run into a formatting problem that...
1
by: Joseph Scoccimaro | last post by:
I am currently working on a project for school dealing with accessing the DOM. I am trying to get access to inner tables that are nested with in other tables. Currently I am able to get all...
29
by: Richard Lionheart | last post by:
Hi All, I've taken the advice of a few people and managed to cobble together an HTML 4.01 Strict-compliant document (according to the W3C Validation Service), but the way I try to pass a...
1
by: =?Utf-8?B?SmVyZW15X0I=?= | last post by:
I am working on an order entry program and have a question related to deserializing nodes with nested elements. The purchase order contains multiple line items which I select using an...
1
by: Henrik Bechmann | last post by:
All, I'm trying to spoof Google's vertical tabs in a vertical menu structured with nested UL/LI elements. To do this, I need to find out where the anchor in the LI is, and then create an...
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
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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.