RE: [xsl] Conditional statements in XSLT

Subject: RE: [xsl] Conditional statements in XSLT
From: cknell@xxxxxxxxxx
Date: Fri, 24 Mar 2006 14:12:56 -0500
Does this help?

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  <xsl:output method="xml" indent="yes" />
  <xsl:strip-space elements="*" />

	<xsl:template match="/">
		<xsl:apply-templates />
	</xsl:template>
	
	
  <xsl:template match="RESULT">
    <RESULT>
      <xsl:apply-templates />
    </RESULT>
  </xsl:template>

  <xsl:template match="OUTPUT" />

  <xsl:template match="PARAMETERS">
   <PARAMETERS>
     <xsl:apply-templates />
     <xsl:copy-of select="/RESULT/OUTPUT/*[name(/RESULT/OUTPUT/*) != name(*)]" />
   </PARAMETERS>
  </xsl:template>

  <xsl:template match="*[parent::PARAMETERS]">
    <xsl:if test="name() != name(/RESULT/OUTPUT/*)">
        <xsl:copy-of select="." />
      </xsl:if>
  </xsl:template>

</xsl:stylesheet>
-- 
Charles Knell
cknell@xxxxxxxxxx - email



-----Original Message-----
From:     Higino Silva <hssilva@xxxxxx>
Sent:     Fri, 24 Mar 2006 17:32:16 -0000
To:       <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Subject:  [xsl] Conditional statements in XSLT

Hi all,

I'm using Xalan J XSLT processor, version 2.7.0, and though I don't have a particular problem with the implementation of Xalan I'm having trouble implementing one of the requirements for our project,  I'm even not sure if is at all possible to do it applying only XSL transformations.
Can anyone advise me on this one?
******* Problem Description: ***********
I have the following input xml document:
<RESULT>
  <PARAMETERS>
    <CYCLE>
      <ENDDATE>20060215</ENDDATE>
    </CYCLE>
    <FILE><CHECK/></FILE>
  </PARAMETERS>
  <OUTPUT>
    <FILE>b</FILE>
    <FILENAME>E:\ftphome\vodafone\xml\CC20060215S50.XML</FILENAME>
  </OUTPUT>
</RESULT>

Now, the resulting xml should have the FILE and FILENAME tags belonging to OUTPUT element transferred to PARAMETERS element, which I can do with no effort at all with the following template:
<--! Coy input node to the output -->
<xsl:template match="*">
       <xsl:copy>
       <xsl:apply-templates />
</xsl:copy>
</xsl:template>
<xsl:template match="OUTPUT"></xsl:template> <!--Output node is not copied to output -->
<--! Copy output nodes to Parameters element -->
<xsl:template match="/RESULT/PARAMETERS">
       <xsl:copy>
       <xsl:copy-of select="/RESULT/OUTPUT/*" />
       <xsl:apply-templates />
       <xsl:copy>
</xsl:template>

The tricky thing here is that if the FILE/FILENAME tag (or any tag under OUTPUT) exists under PARAMETERS, then the tag under PARAMETERS should be overwritten by correspondent OUTPUT tag. In this case the correct output should be the following:
<RESULT>
  <PARAMETERS>
    <CYCLE>
      <ENDDATE>20060215</ENDDATE>
    </CYCLE>
   <FILE>b</FILE>
   <FILENAME>E:\ftphome\vodafone\xml\CC20060215S50.XML</FILENAME>
  </PARAMETERS>
</RESULT>

I would much appreciate some help,.

Many many thanks
Higino Silva



AVISO

Esta mensagem e quaisquer anexos seus podem conter informagco confidencial para uso exclusivo do destinatario. Cabe ao destinatario assegurar a verificagco de vmrus e outras medidas que assegurem que esta mensagem nco afecta os seus sistemas. Se nco for o destinatario, nco devera usar, distribuir ou copiar este e-mail, devendo proceder ` sua eliminagco e informar o emissor. I estritamente proibido o uso, a distribuigco, a cspia ou qualquer forma de disseminagco nco autorizada deste e-mail e seus anexos. Obrigado.

DISCLAIMER
This e-mail and its attachments may contain confidential information for exclusive use of its recipient. It is your responsibility to carry out appropriate virus and other checks to ensure that this message and any attachments do not affect your systems / data. If you are not the intended recipient you must not use, distribute or reproduce this e-mail and you must notify the sender and delete the entire email. Any unauthorized use, dissemination, distribution or copying of this message and its attachments is strictly prohibited. Thank You.

Current Thread