[thelist] XSL translation

Marcus Andersson marcus at bristav.se
Mon Mar 1 09:06:38 CST 2004


Nick Lester wrote:
Try this one:

  <xsl:template match="/data">
     <xsl:apply-templates select="record"/>
   </xsl:template>

   <xsl:template match="record">
     <record Title="{@Title}">
       <xsl:for-each select="@*[name() != 'Title']">
         <xsl:element name="{name()}">
           <xsl:value-of select="."/>
         </xsl:element>
       </xsl:for-each>
     </record>
   </xsl:template>

/Marcus

> Hi
> 
> I Asked this question a while back but I deleted the answer by mistake!!
> 
> I have an XML  doc like below
> 
> <?xml version="1.0"?>
> <data>
> <record Title="Mr" Forename="Nick" Surname="Lester" />
> <record Title="Mr" Forename="Joe" Surname="Bloggs" />
> </data>
> 
> I need an XSLT transformation that turns it into
> 
> <data>
>   <record Title="Mr">
>    <Forename>Nick</Forename>
>    <Surname>Lester</Surname>
>   </record>
>   <record Title="Mr">
>    <Forename>Joe</Forename>
>    <Surname>Bloggs</Surname>
>   </record
> </data>
> 
> 
> All nodes apart from Title can may be different, that is they cant be
> hardcoded into the XSL as new nodes may be addes / removed such as
> <Address> <Telephone>   etc...
> 
> Thanks ever so much in advance...
> 
> Nick
> 
> 
> 




More information about the thelist mailing list