This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

FW: xsl:transform


Thanks a lot Dimitre.

If you don't mind, can I raise another one ?
Let's assume that the attribute col1 in <xref/file1> need to 
be transform into element label1/sub-label1 ( and col2 in <xref/file2> as
well ) :
<xref>
    <file1>
 
<abbr>col1</abbr><header>label1</header><subheader>sub-label1</subheader>
        <abbr>col2</abbr><header>label2</header>
        <abbr>col3</abbr><header>label3</header>
        <abbr>col4</abbr><header>label4</header>
        <abbr>col5</abbr><header>label5</header>
    </file1>
    <file2>
        <abbr>col1</abbr><header>label1</header>
 
<abbr>col2</abbr><header>label2</header><subheader>sub-label2</subheader>
    </file2>
</xref>

As I'm still learning about XSLT, I rename the <name> element in
<xref/file1> and <xref/file2>
into <header> ( as I got confused with 'name' as variable, function, etc ).

In fact, my generic question is how to deal if any <abbr> in <xref/file1> or
<xref/file2>
have more than one sibbling ( i.e. col3 have <subheader> element as well ) ?

Cheers,
Benoit.


> -----Original Message-----
> From: Dimitre Novatchev [mailto:dnovatchev@yahoo.com] 
> Sent: 23 June 2001 06:12
> To: Benoit_Aumars@jltgroup.com
> Cc: xsl-list@lists.mulberrytech.com
> Subject: Re: xsl:transform
> 
> 
> Benoit_Aumars@jltgroup.com wrote:
> >
> >I would like to transform from one xml into another one
> >using a 'lookup'  xml file.
> >
> >Here is the original xml file :
> >
> ><?xml version="1.0"?>
> ><file1>
> >    <col1>01</col1>
> >    <col2>Hello</col2>
> >    <col3>world</col3>
> >    <col4>GTP</col4>
> >    <col5>02 Jul 1999 09:45:05:706</col5>
> ></file1>
> >
> >using this 'lookup' xml file :
> ><?xml version="1.0"?>
> ><xref>
> >    <file1>
> >	<abbr>col1</abbr><name>label1</name>
> >	<abbr>col2</abbr><name>label2</name>
> >	<abbr>col3</abbr><name>label3</name>
> >	<abbr>col4</abbr><name>label4</name>
> >	<abbr>col5</abbr><name>label5</name>
> >    </file1>
> >    <file2>
> >	<abbr>col1</abbr><name>header1</name>
> >	<abbr>col2</abbr><name>header2</name>
> >    </file2>
> ></xref>
> >
> >
> >the xml result is :
> ><?xml version="1.0"?>
> ><file1>
> >    <label1>01</label1>
> >    <label2>Hello</label2>
> >    <label3>world</label3>
> >    <label4>GTP</label4>
> >    <label5>02 Jul 1999 09:45:05:706</label5>
> ></file1>
> >
> >If the original xml file :
> >
> ><?xml version="1.0"?>
> ><file2>
> >    <col1>12345</col1>
> >    <col2>Welcome</col2>
> ></file2>
> >
> >using the same 'lookup' xml file, the result is :
> ><?xml version="1.0"?>
> ><file2>
> >    <header1>12345</header1>
> >    <header2>Welcome</header2>
> ></file2>
> >
> >Any idea how to ?
> 
> 
> Hi Ben,
> 
> Use the same solution as I posted yesterday 
> (http://sources.redhat.com/ml/xsl-list/2001-06/msg01004.html)
> 
> You've changed a little the problem -- the input arguments 
> are elements -- not
> attributes as before. More importantly, your lookup file now 
> has different sections
> and you specify (the name of the top element of the input xml 
> file) the name of the
> section that must be used in the lookup.
> 
> Therefore, the previous solution is changed accordingly:
> 
> <xsl:stylesheet version="1.0" 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
>   <xsl:output indent="yes" omit-xml-declaration="yes"/>
>   <xsl:key name="kLookup" match="name" 
> use="preceding-sibling::abbr[1]"/>
>   <xsl:variable name="lookupSection" select="name(/*)"/>
>   
>   <xsl:template match="/">
>     <xsl:element name="{name(*)}">
>       <xsl:apply-templates select="/*/*"/>
>     </xsl:element>
>   </xsl:template>
> 
>   <xsl:template match="*">
>      <xsl:variable name="input" select="."/>
>      <xsl:for-each select="document('lookup.xml')">
>         <xsl:for-each select="key('kLookup', name($input))
>                                                   
> [$lookupSection = name(..)]">
>           <xsl:element name="{.}">
>            <xsl:value-of select="$input"/>
>           </xsl:element>
>         </xsl:for-each>
>      </xsl:for-each>
>   </xsl:template>
> </xsl:stylesheet> 
> 
> This, as the previous solution, has been tested and verified 
> to work as expected.
> 
> Cheers,
> Dimitre Novatchev.
> 
> __________________________________________________
> Do You Yahoo!?
> Get personalized email addresses from Yahoo! Mail
> http://personal.mail.yahoo.com/
> 


************************************************************
JLT Management Services Limited
6 Crutched Friars, London EC3N 2PH. Co Reg No 1536540
Tel: (44) (0)20 7528 4000   Fax: (44) (0)20 7528 4500
http://www.jltgroup.com
------------------------------------------------------------
The content of this e-mail (including any attachments) as 
received may not be the same as sent. If you consider that 
the content is material to the formation or performance of 
a contract or you are otherwise relying upon its accuracy, 
you should consider requesting a copy be sent by facsimile 
or normal mail.  The information in this e-mail is 
confidential and may be legally privileged. If you are not 
the intended recipient, please notify the sender immediately 
and then delete this e-mail entirely - you must not retain, 
copy, distribute or use this e-mail for any purpose or 
disclose any of its content to others.

Opinions, conclusions and other information in this e-mail 
that do not relate to the official business of JLT 
Management Services Limited shall be understood as neither 
given nor endorsed by it.  Please note we intercept and 
monitor incoming / outgoing e-mail and therefore you should 
neither expect nor intend any e-mail to be private in nature.

We have checked this e-mail for viruses and other harmful 
components and believe but not guarantee it virus-free prior 
to leaving our computer system.  However, you should satisfy 
yourself that it is free from harmful components, as we do 
not accept responsibility for any loss or damage it may 
cause to your computer systems.
************************************************************

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]