Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: XSLT conversion

From: "Han" <hp4444@------.---.----->
To: NULL
Date: 4/26/2004 10:22:00 PM
I missed the recursion and dynamic depth part. Try this call-template.

<xsl:stylesheet
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 version="1.0">
<xsl:output method='xml'
 indent='yes' omit-xml-declaration='yes'/>

<xsl:template match="HEADER.COL">
<xsl:call-template name='t'>
 <xsl:with-param name='p1' select='.'/>
</xsl:call-template>
</xsl:template>

<xsl:template name='t'>
 <xsl:param name='p1'/>
 <xsl:variable name='v1'
select="count($p1//HD.C[not(following::HD.C)])*2-2"/>
 <ROW>
 <xsl:for-each select="$p1/HD.C">
 <CELL SPAN="{$v1}">
  <xsl:value-of select="normalize-space(text()[parent::HD.C])"/>
 </CELL>
 </xsl:for-each>
 </ROW>

 <xsl:if test="$p1/HD.C">
  <xsl:call-template name='t'>
   <xsl:with-param name='p1' select='$p1/HD.C'/>
  </xsl:call-template>
 </xsl:if>

</xsl:template>

<xsl:template match="@* | node()">
<xsl:copy>
 <xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>

THE RESULT IS AS FOLLOWS. I THINK YOU'LL DO YOUR HOUSE KEEPING.

<TEST>
 <ROW>
  <CELL SPAN="4">Mondial</CELL>
  <CELL SPAN="4">EEE</CELL>
  <CELL SPAN="4">Portugal</CELL>
 </ROW>
 <ROW>
  <CELL SPAN="2">Volume</CELL>
  <CELL SPAN="2">Quantit?</CELL>
  <CELL SPAN="2">Volume</CELL>
  <CELL SPAN="2">Quantit?</CELL>
  <CELL SPAN="2">Volume</CELL>
  <CELL SPAN="2">Quantit?</CELL>
 </ROW>
 <ROW>
  <CELL SPAN="0">kg</CELL>
  <CELL SPAN="0">tonnes</CELL>
  <CELL SPAN="0">kg</CELL>
  <CELL SPAN="0">tonnes</CELL>
  <CELL SPAN="0">kg</CELL>
  <CELL SPAN="0">tonnes</CELL>
  <CELL SPAN="0">kg</CELL>
  <CELL SPAN="0">tonnes</CELL>
  <CELL SPAN="0">kg</CELL>
  <CELL SPAN="0">tonnes</CELL>
  <CELL SPAN="0">kg</CELL>
  <CELL SPAN="0">tonnes</CELL>
 </ROW>
 <ROW></ROW>
</TEST>


"Olivier VEIT" <olivier.veit@f...> wrote in message
news:c6ih7g$ovt$1@n......
> Sorry, were was i little mistake in the output I need. It is :
>
> OUTPUT i Need :
>  =================
>
>  <?xml version="1.0" encoding="ASCII"?>
>  <TEST>
>      <ROW>
>              <CELL COLSPAN="4">Mondial</CELL>
>              <CELL COLSPAN="4">EEE</CELL>
>              <CELL COLSPAN="4">Portugal</CELL>
>      </ROW>
>      <ROW>
>              <CELL COLSPAN="2">Volume</CELL>
>              <CELL COLSPAN="2">Quantit?/CELL>
>              <CELL COLSPAN="2">Volume</CELL>
>              <CELL COLSPAN="2">Quantit?/CELL>
>              <CELL COLSPAN="2">Volume</CELL>
>              <CELL COLSPAN="2">Quantit?/CELL>
>      </ROW>
>      <ROW>
>              <CELL>kg</CELL>
>              <CELL>tonnes</CELL>
>              <CELL>kg</CELL>
>              <CELL>tonnes</CELL>
>              <CELL>kg</CELL>
>              <CELL>tonnes</CELL>
>              <CELL>kg</CELL>
>              <CELL>tonnes</CELL>
>              <CELL>kg</CELL>
>              <CELL>tonnes</CELL>
>              <CELL>kg</CELL>
>              <CELL>tonnes</CELL>
>      </ROW>
>  </TEST>
>
>
> "Olivier VEIT" <olivier.veit@f...> a ?rit dans le message de
> news:c6igv0$nri$1@n......
> > Hello,
> >
> > thanks, but your solution is only possible for this exemple. The
> stylesheet
> > should be dynamic and treat a undefined number of imbricated HD.C.
> > The COLSPAN attribute should also be generated dynamically. I think the
> only
> > solution is to use recursion...but how ?
> > Here, an other exemple :
> >
> > INPUT :
> > =======
> > <?xml version="1.0" encoding="UTF-8"?>
> >
> > <TEST>
> >     <HEADER.COL>
> >         <HD.C>Mondial
> >                 <HD.C TYPE="INT">Volume
> >                         <HD.C>kg</HD.C>
> >                         <HD.C>tonnes</HD.C>
> >                 </HD.C>
> >                 <HD.C TYPE="INT">Quantit?
> >                     <HD.C>kg</HD.C>
> >                     <HD.C>tonnes</HD.C>
> >                 </HD.C>
> >         </HD.C>
> >         <HD.C>EEE
> >                 <HD.C TYPE="INT">Volume
> >                     <HD.C>kg</HD.C>
> >                     <HD.C>tonnes</HD.C>
> >                     </HD.C>
> >                 <HD.C TYPE="INT">Quantit?
> >                     <HD.C>kg</HD.C>
> >                     <HD.C>tonnes</HD.C>
> >                 </HD.C>
> >         </HD.C>
> >         <HD.C>Portugal
> >                 <HD.C TYPE="INT">Volume
> >                             <HD.C>kg</HD.C>
> >                         <HD.C>tonnes</HD.C>
> >                 </HD.C>
> >                 <HD.C TYPE="INT">Quantit?
> >                         <HD.C>kg</HD.C>
> >                         <HD.C>tonnes</HD.C>
> >                 </HD.C>
> >         </HD.C>
> >     </HEADER.COL>
> > </TEST>
> >
> > OUTPUT i Need :
> > =================
> >
> > <?xml version="1.0" encoding="ASCII"?>
> > <TEST>
> >     <ROW>
> >             <CELL COLSPAN="4">Mondial</CELL>
> >             <CELL COLSPAN="4">EEE</CELL>
> >             <CELL COLSPAN="4">Portugal</CELL>
> >     </ROW>
> >     <ROW>
> >             <CELL COLSPAN="2">Volume</CELL>
> >             <CELL COLSPAN="2">Quantit?/CELL>
> >             <CELL COLSPAN="2">Volume</CELL>
> >             <CELL COLSPAN="2">Quantit?/CELL>
> >             <CELL COLSPAN="2">Volume</CELL>
> >             <CELL COLSPAN="2">Quantit?/CELL>
> >     </ROW>
> >     <ROW>
> >             <CELL>kg</CELL>
> >             <CELL>tonnes</CELL>
> >             <CELL>kg</CELL>
> >             <CELL>tonnes</CELL>
> >             <CELL>kg</CELL>
> >             <CELL>tonnes</CELL>
> >             <CELL>kg</CELL>
> >             <CELL>tonnes</CELL>
> >     </ROW>
> > </TEST>
> >
> >
> >
> > "Han" <hp4444@k...> a ?rit dans le message de
> > news:ONThnxoKEHA.2576@T......
> > > Try,
> > >
> > > <xsl:stylesheet
> > >  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> > >  version="1.0">
> > > <xsl:output method='xml' indent='yes' omit-xml-declaration='yes'/>
> > >
> > > <xsl:template match="/">
> > > <TEST>
> > >     <ROW>
> > >         <CELL COLSPAN="2">Mundial</CELL>
> > >         <CELL COLSPAN="2">EEE</CELL>
> > >         <CELL COLSPAN="2">Portugal</CELL>
> > >     </ROW>
> > >     <ROW>
> > >   <xsl:apply-templates select="//HD.C/HD.C"/>
> > >  </ROW>
> > > </TEST>
> > > </xsl:template>
> > >
> > > <xsl:template match='HD.C'>
> > >  <CELL>
> > >  <xsl:value-of select='.'/>
> > >  </CELL>
> > > </xsl:template>
> > >
> > > </xsl:stylesheet>
> > >
> > > "Olivier VEIT" <olivier.veit@f...> wrote in message
> > > news:c6b5bq$6fh$1@n......
> > > > Hello All,
> > > >
> > > > I would like to write a stylesheet enbling me to get the end
structure
> > > from
> > > > start structu.
> > > >
> > > > My start structure :
> > > > ==============
> > > > <TEST>
> > > >     <HEADER.COL>
> > > >         <HD.C>Mundial
> > > >             <HD.C TYPE="INT">Volume 1</HD.C>
> > > >             <HD.C TYPE="INT">Test 1</HD.C>
> > > >         </HD.C>
> > > >         <HD.C>EEE
> > > >             <HD.C TYPE="INT">Volume 2</HD.C>
> > > >             <HD.C TYPE="INT">Test 2</HD.C>
> > > >         </HD.C>
> > > >         <HD.C>Portugal
> > > >             <HD.C TYPE="INT">Volume 3</HD.C>
> > > >             <HD.C TYPE="INT">Test 3</HD.C>
> > > >         </HD.C>
> > > >     </HEADER.COL>
> > > > </TEST>
> > > >
> > > > This is the end structure I would like to have :
> > > > ======================================
> > > > <TEST>
> > > >     <ROW>
> > > >         <CELL COLSPAN="2">Mundial</CELL>
> > > >         <CELL COLSPAN="2">EEE</CELL>
> > > >         <CELL COLSPAN="2">Portugal</CELL>
> > > >     </ROW>
> > > >     <ROW>
> > > >         <CELL>Volume 1</CELL>
> > > >         <CELL>Test 1</CELL>
> > > >         <CELL>Volume 2</CELL>
> > > >         <CELL>Test 2</CELL>
> > > >         <CELL>Volume 3</CELL>
> > > >         <CELL>Test 3</CELL>
> > > >     </ROW>
> > > > </TEST>
> > > >
> > > > The solution should be general so that it also works with multiple
> HD.C
> > > > imbrications.
> > > >
> > > > Thanks for your answers
> > > >
> > > > Have a nice Day
> > > >
> > > > Olivier
> > > >
> > > >
> > >
> > >
> >
> >
>
>




transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent