Jump to content

One Xslt To Transform Two Xml Files


sacha74

Recommended Posts

Hello, I would like to transform those two examples :

<topic><body><p><table><tgroup cols="3"><colspec colname="1" colnum="1" colwidth="25%"/><colspec colname="2" colnum="2" colwidth="55%"/><colspec colname="3" colnum="3" colwidth="20%"/><thead></thead><tbody><row><entry><p>Conditions à respecter :</p><ul><li>Renseigner ...</li>	<li>Renseigner les champs "Obligatoires"  :		<table>			<thead>				<tr>					<th scope="col">Code opération</th>					<th scope="col">Champs</th>					<th scope="col">Mot clé</th>				</tr>			</thead>			<tbody>				<tr>					<td>CPS (Paiem.Coup.)</td>					<td>Date EX					Date Paiement Cash</td>					<td>					<p>DEX					DPC</p>					</td>				</tr>			</tbody>		</table>	</li></ul></entry></row></tbody></tgroup></table></p></body></topic>

The second one :

<topic><body><table> <tr> <th> </th> <th> Autre numérotation du centre 0000001 </th> <th> Racine (positions 2 à 5) à contrôler </th> <th> 0 </th> </tr><tbody> <tr> <td> </td> <td> </td> <td> </td></tr></tbody></table></body></topic>

I would like to transform those file using one XSLT file :

<xsl:template match="entry//table[descendant::tr]">

this one works for the first example

<xsl:template match="table[descendant::tr]">

this one works for the second example.I have tried :-

<xsl:template match="entry//table[descendant::tr]|table[descendant::tr]"> 

but it works only for the second example-

<xsl:template match="*//table[descendant::tr]"> 

but it works only for the second example.- several other possible solutions and I can't find one that it works ! Do you have any idea to put together thes two codes. Thanks in advance for the help I could find.

Link to comment
Share on other sites

Hello, I tried to put a new xsl:for each inside the treatment I already do for table (shown in the xslt file of the previous message) because the table is in a table.It doesn't work better than the first code I mentionned yesterday in the code below.Here is my new code :

<xsl:template match="@*|node()">  <xsl:copy>   <xsl:apply-templates select="@*|node()"/>  </xsl:copy></xsl:template> <xsl:template match="table[descendant::tr]">  <table>   <tgroup>	<xsl:attribute name="cols"><xsl:value-of select="count(.//th)"/></xsl:attribute>  	<xsl:for-each select="thead/tr">	 <thead>	  <row>	   <xsl:for-each select="th">		<entry>		 <xsl:apply-templates/>		</entry>	   </xsl:for-each>	  </row>	 </thead>	</xsl:for-each>  	<xsl:for-each select="tr[(descendant::th)]">	 <thead>	  <row>	   <xsl:for-each select="th">		<entry>		 <xsl:apply-templates/>		</entry>	   </xsl:for-each>	  </row>	 </thead>	</xsl:for-each>  	<xsl:for-each select="tbody/tr[(descendant::th)]">	 <thead>	  <row>	   <xsl:for-each select="th">		<entry>		 <xsl:apply-templates/>		</entry>	   </xsl:for-each>	  </row>	 </thead>	</xsl:for-each>  	<tbody>	 <xsl:for-each select="tbody/tr[not(descendant::th)]">	  <row>	   <xsl:for-each select="td">		<entry>		<xsl:for-each select="entry//table">		<table>		  <tgroup>		   <xsl:attribute name="cols"><xsl:value-of select="count(.//th)"/></xsl:attribute>  			<xsl:for-each select="thead/tr">			 <thead>			 <row>			 <xsl:for-each select="th">			  <entry>				<xsl:apply-templates/>			  </entry>			 </xsl:for-each>			 </row>			 </thead>			</xsl:for-each>			<tbody>			<xsl:for-each select="tbody/tr">			  <row>			   <xsl:for-each select="td">				<entry>				 <xsl:apply-templates/>				</entry>			   </xsl:for-each>			  </row>			 </xsl:for-each>			</tbody>			</tgroup>			</table>			</xsl:for-each>		</entry>	   </xsl:for-each>	  </row>	 </xsl:for-each>	</tbody>   </tgroup>  </table></xsl:template></xsl:stylesheet>

I think I'm really at a dead end. So if anyone has any idea, any indication that could help me, please tell me. Thanks in advance for the help I could find.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...