[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] transformation of narrative documents with nested elements

Subject: Re: [xsl] transformation of narrative documents with nested elements
From: Raffaele Sena <raff@xxxxxxxxxxxx>
Date: Sun, 16 Jan 2005 09:56:34 -0800

Try changing the templates for "bold" and "emph" to:

<xsl:template match="bold">
  <strong><xsl:apply-templates select="."/></strong>

<xsl:template match="emph">
  <i><xsl:apply-templates select="."/></i>

This should let you process one formatting tag inside the other (and the text should be generated by the default template for "text()").

-- Raffaele

On Jan 16, 2005, at 10:26 AM, Andrea Fiore wrote:

I am an xml-xsl newbie, and I'm writing some xsl templates for a small CMS that I'm coding,
using PHP(+Dom extension) and MySql. At the moment i have some problems in the html transformation of this file called news_list.xml.
consider the following xml source:
1 <?xml version="1.0" encoding="iso-8859-1"?>
2 <news_list>
4 <!-- other news -->
6 <news id="1" topic="a_topic">
7 <title lang="en"> The English title </title>
8 <title lang="it"> the Italian title </title>
9 <author> me </author>
11 <date lang="en" day="16" month="January" year="2005"/>
12 <date lang="it" day="16" month="Gennaio" year="2005"/>
14 <text lang="en">
15 <bold>This is a bold text </bold>
16 <emph> This is an italic text </emph>
17 <bold>this is <emph> an italic text nested</emph> inside a bold text </bold> <!-- here is my problem -->
18 </text>
19 <text lang="it">
20 bla bla bla in italian...
21 </text>
23 </news>
24 <!-- other news -->
25 </news_list>

I would like to transform this in html, according to the following goals:

* I have to select only the news where an English title is available

* I have to transform all the elements inside the English description,
and they may occur as nested elements, as in line 17: X PATH: /news_list/news/description[lang='it']/bold/emph
at the moment i wrote this stylesheet, that does not achieve the second goal: i have a correct output for line 15 and 16, but i have no output for line 17

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="iso-8859-1"/>

 <xsl:template match="/">
  <div class="news_list">
    <xsl:apply-templates select="/news_list/news"/>
   <xsl:template match="/news_list/news">
   <xsl:if test="title[@lang='en']">
       <xsl:when test="position()=1">
        <div class="first_news">
         <xsl:call-template name="news_en"/><br/>
        <div class="news">
         <xsl:call-template name="news_en"/><br/>
   </xsl:if>     </xsl:template>

<xsl:template name="news_en">
<sup id="position_number">
<xsl:value-of select="position()"/>
<big class="news_title"><xsl:value-of select="title[@lang='en']"/></big>
<div class="text_en">
<xsl:apply-templates select="text[@lang='en']"/>

  <xsl:template match="text[@lang='en']">
   <xsl:template match="//bold">
    <xsl:element name="strong">
      <xsl:value-of select="."/>
    </xsl:element>           </xsl:template>

  <xsl:template match="//emph">
    <xsl:element name="i">
      <xsl:value-of select="."/>
    </xsl:element>           </xsl:template>

I tested this stylesheet also with xslproc, so i think this is not a problem
of the PhpDom implementation, but a problem in my XPATH sintax.....

Thank you in advance for your attention,



Current Thread