RE: [xsl] Creating multiple nodes from a source node data

Subject: RE: [xsl] Creating multiple nodes from a source node data
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 18 Sep 2009 09:11:43 +0100
> I'm trying to find a way to transform an XML element text and 
> form elements using that text.
> 
> I/P XML
> 
> <info>
>         <p> Name:</p>
>          </nl>emp1
>          <p>Emp No:</P>
>          </nl>1234
>          <p>address:</p>
>          </nl>address1
>          </nl>---------------
>          <p>Name:</p>
>          </nl>emp2
>          <p>Emp No:</p>
>          </nl>12345
>          <p>address:</p>
>          </nl>address2
> </info>

I hope that's not your input, because it's not XML. But assuming that's just
carelessness, the way to solve this kind of problem in XSLT 2.0 is with

<xsl:template match="info">
  <xsl:for-each-group select="node()"
group-starting-with="text()[.='------------']">
    <emp>
      <xsl:apply-templates select="current-group()"/>
    </emp>
  </
</

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay 


> 
> Desired O/P XML
> 
> <emp>
>          <empinfo>
>                        <empname>emp1</empname>
>                        <empno>1234</empno>
>                        </empinfo>
>         <empaddress>
>                        <address>address1</address>
>         </empaddress>
> </emp>
> <emp>
>          <empinfo>
>                       <empname>emp2</empname>
>                       <empno>12345</empno>
>                       </empinfo>
>          <empaddress>
>                       <address>address2</address>
>          </empaddress>
> </emp>
> 
> In input XML ------------ is a delimiter which signifies the 
> starting of new emp info.
> I'm using XSL version 2.0, can the gurus please suggest me a 
> way to achieve this.
> 
> --
> Regards,
> Byran

Current Thread