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

Re: unfold one element to several elements according t

Subject: Re: unfold one element to several elements according to its attribute
From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx>
Date: Sun, 25 May 2008 23:07:03 +0530
Re:  unfold one element to several elements according t
Following is a working 2.0 stylesheet somewhat similar to Martin's solution:

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

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

<xsl:template match="root">
    <xsl:apply-templates select="product" />

<xsl:template match="product">
  <xsl:variable name="x" select="." />
  <xsl:for-each select="tokenize(@owner,',')">
      <xsl:copy-of select="$x/@*[not(name() = 'owner')]" />
      <xsl:attribute name="owner">
        <xsl:value-of select="." />
        <xsl:value-of select="$x/title[contains(@owner, current())]" />


This when applied to the XML:

<?xml version="1.0" encoding="UTF-8"?>
  <product id="1" owner="a,b,c">
   <title owner="a,b">foo</title>
   <title owner="c">bar</title>
  <product id="2" owner="p,q">
     <title owner="q">abc</title>
     <title owner="p">pqr</title>

produces output:

<?xml version="1.0" encoding="UTF-8"?>
   <product id="1" owner="a">
   <product id="1" owner="b">
   <product id="1" owner="c">
   <product id="2" owner="p">
   <product id="2" owner="q">

On Sun, May 25, 2008 at 10:36 PM, mixhere <mixhere@xxxxxxxxx> wrote:
> Hello everyone,
> is it possible to do the translation? you can add other
> elements/attributes in the original xml if the info is not enough.
> thanks.
> Original:
> <product id="1" owner="a,b,c">
> <title owner="a,b">foo</title>
> <title owner="c">bar</title>
> </product>
> After translation:
> <product id="1" owner="a">
> <title>foo</title>
> </product>
> <product id="1" owner="b">
> <title>foo</title>
> </product>
> <product id="1" owner="c">
> <title>bar</title>
> </product>

Mukul Gandhi

Current Thread


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.
First Name
Last Name
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.