[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Re: How to merge two elements and transform them i

Subject: Re: Re: How to merge two elements and transform them into a table
From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx>
Date: Sat, 17 May 2008 13:33:15 +0530
Re:  Re: How to merge two elements and transform them i
You need to use a tokenizing functionality to solve this problem. You
can use an EXSLT extension for this.

Following is a working solution for this problem:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
		        xmlns:str="http://exslt.org/strings"
		        exclude-result-prefixes="str"
                        version="1.0">

<xsl:output method="html" />

<xsl:template match="/">
  <html>
    <head>
      <title/>
    </head>
    <body>
      <table>
        <xsl:variable name="actors"
select="str:tokenize(Items/Item/Actors,'|')" />
        <xsl:variable name="actorsrole"
select="str:tokenize(Items/Item/Actorsrole,'|')" />
        <xsl:for-each select="$actors">
          <xsl:variable name="x" select="position()" />
          <tr>
            <td>
              <xsl:value-of select="." />
            </td>
            <td>
              <xsl:value-of select="$actorsrole[position() = $x]" />
            </td>
          </tr>
        </xsl:for-each>
      </table>
    </body>
  </html>
</xsl:template>

</xsl:stylesheet>

On Sat, May 17, 2008 at 12:39 PM, Erik Vullings <erik.vullings@xxxxxxxxx> wrote:
> Hi,
>
> I am trying to convert movie details (from http://www.movie-xml.com)
> into a nice HTML page. That works quite well, except for the actor
> name/role part, which is in two separate nodes for all actors and
> roles - see the Actors and ActorsRole node below:
> <Items>
>    <Item>
>        <SeriesName>101 Dalmatians</SeriesName>
>        <Actors>|Glenn Close|Jeff Daniels|Joely Richardson|Joan
> Plowright|Hugh Laurie|Mark Williams|John Shrapnel|</Actors>
>        <Actorsrole>|Cruella De
> Vil|Roger|Anita|Nanny|Jasper|Horace|Skinner|</Actorsrole>
>        <Tagline>So many dogs. So little time.</Tagline>
>    </Item>
> </Items>
>
> What I would like to obtain is something like the following (in a HTML
> table - please also note that the '|' should be removed):
> Glenn Close       Cruella De Vil
> Jeff Daniels        Roger
> etc.
>
> I'm quite new to XSLT, and couldn't find anything useful using Google,
> so can it be done using XSLT (preferably v1.0)? Any help would be much
> appreciated!
>
> Cheers
> Erik


-- 
Regards,
Mukul Gandhi

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.