  | |  | Conditional statements in XSLT | Conditional statements in XSLT 2006-03-24 - By Higino Silva
Hi all,
I'm using Xalan J, and though I don't have a particular problem with the implementation of Xalan I'm having troubles 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:
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, and since I'm not sure I'm using the right mailing list, please accept my apologies and please guide to a correct one.
Many many thanks
Higino Silva
AVISO
Esta mensagem e quaisquer anexos seus podem conter informacao confidencial para uso exclusivo do destinatario. Cabe ao destinatario assegurar a verificacao de virus e outras medidas que assegurem que esta mensagem nao afecta os seus sistemas. Se nao for o destinatario, nao devera usar, distribuir ou copiar este e-mail, devendo proceder a sua eliminacao e informar o emissor. E estritamente proibido o uso, a distribuicao, a copia ou qualquer forma de disseminacao nao 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.
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft -com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:x="urn :schemas-microsoft-com:office:excel" xmlns:p="urn:schemas-microsoft-com:office :powerpoint" xmlns:oa="urn:schemas-microsoft-com:office:activation" xmlns="http: //www.w3.org/TR/REC-html40">
<head> <meta http-equiv=Content-Type content="text/html; charset=us-ascii"> <meta name=Generator content="Microsoft Word 11 (filtered medium)"> <style> <!-- /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {margin:0cm; margin-bottom:.0001pt; font-size:12.0pt; font-family:"Times New Roman";} a:link, span.MsoHyperlink {color:blue; text-decoration:underline;} a:visited, span.MsoHyperlinkFollowed {color:purple; text-decoration:underline;} p {mso-margin-top-alt:auto; margin-right:0cm; mso-margin-bottom-alt:auto; margin-left:0cm; font-size:12.0pt; font-family:"Times New Roman";} span.EmailStyle17 {mso-style-type:personal-compose; font-family:Arial; color:blue; font-weight:normal; font-style:normal; text-decoration:none none;} @(protected) Section1 {size:595.3pt 841.9pt; margin:70.85pt 3.0cm 70.85pt 3.0cm;} div.Section1 {page:Section1;} --> </style> <!--[if gte mso 9]><xml> <o:shapedefaults v:ext="edit" spidmax="1026" /> </xml><![endif]--><!--[if gte mso 9]><xml> <o:shapelayout v:ext="edit"> <o:idmap v:ext="edit" data="1" /> </o:shapelayout></xml><![endif]--> </head>
<body lang=PT link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal><font size=2 color=blue face="Courier New"><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:blue'>Hi all,<o:p></o:p ></span></font></p>
<p class=MsoNormal><font size=2 color=blue face="Courier New"><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:blue'><o:p> </o:p> </span></font></p>
<p class=MsoNormal><font size=2 color=blue face=Arial><span lang=EN-US style='font-size:10.0pt;font-family:Arial;color:blue'>I’m using Xalan J, and though I don’t have a particular problem with the implementation of Xalan I’m having troubles 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.<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=blue face=Arial><span lang=EN-US style='font-size:10.0pt;font-family:Arial;color:blue'>Can anyone advise me on this one:<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=blue face=Arial><span lang=EN-US style='font-size:10.0pt;font-family:Arial;color:blue'> <o:p></o:p></span>< /font></p>
<p class=MsoNormal><font size=2 color=blue face=Arial><span lang=EN-US style='font-size:10.0pt;font-family:Arial;color:blue'>I have the following input xml document:<o:p></o:p></span></font></p>
<p style='margin:0cm;margin-bottom:.0001pt'><font size=2 color=navy face="Courier New"><span lang=EN-US style='font-size:10.0pt;font-family: "Courier New"; color:navy'><RESULT></span></font><font face="Courier New"><span style='font-family:"Courier New"'><o:p></o:p></span></font></p>
<p style='margin:0cm;margin-bottom:.0001pt'><font size=2 color=navy face="Courier New"><span lang=EN-US style='font-size:10.0pt;font-family: "Courier New"; color:navy'> <PARAMETERS></span></font><font face="Courier New"> <span style='font-family:"Courier New"'><o:p></o:p></span></font></p>
<p style='margin:0cm;margin-bottom:.0001pt'><font size=2 color=navy face="Courier New"><span lang=EN-US style='font-size:10.0pt;font-family: "Courier New"; color:navy'> <CYCLE></span></font><font face="Courier New"><span style='font-family:"Courier New"'><o:p></o:p></span>< /font></p>
<p style='margin:0cm;margin-bottom:.0001pt'><font size=2 color=navy face="Courier New"><span lang=EN-US style='font-size:10.0pt;font-family: "Courier New"; color:navy'> <ENDDATE>20060215</ENDDATE></span></font><font face="Courier New"> <span style='font-family:"Courier New"'><o:p></o:p></span></font></p>
<p style='margin:0cm;margin-bottom:.0001pt'><font size=2 color=navy face="Courier New"><span lang=EN-US style='font-size:10.0pt;font-family: "Courier New"; color:navy'> </CYCLE><o:p></o:p></span></font></p>
<p style='margin:0cm;margin-bottom:.0001pt'><font size=2 color=navy face="Courier New"><span lang=EN-US style='font-size:10.0pt;font-family: "Courier New"; color:navy'> <FILE><CHECK/></FILE></span>< /font><font face="Courier New"><span style='font-family:"Courier New"'><o:p></o:p></span>< /font></p>
<p style='margin:0cm;margin-bottom:.0001pt'><font size=2 color=navy face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New"; color:navy'> </PARAMETERS><o:p></o:p></span></font></p>
<p style='margin:0cm;margin-bottom:.0001pt'><font size=2 color=navy face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New"; color:navy'> <OUTPUT></span></font><font face="Courier New"><span style='font-family:"Courier New"'><o:p></o:p></span></font></p>
<p style='margin:0cm;margin-bottom:.0001pt'><font size=2 color=navy face="Courier New"><span lang=EN-US style='font-size:10.0pt;font-family: "Courier New"; color:navy'> <FILE>b</FILE></span></font><font face="Courier New"><span style='font-family:"Courier New"'><o:p></o:p></span>< /font></p>
<p style='margin:0cm;margin-bottom:.0001pt'><font size=2 color=navy face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New"; color:navy'> <FILENAME>E:\ftphome\vodafone<wbr>\xml \CC20060215S50.XML<<wbr>/FILENAME><o:p></o:p></span></font></p>
<p style='margin:0cm;margin-bottom:.0001pt'><font size=2 color=navy face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New"; color:navy'> </OUTPUT></span></font><font face="Courier New"><span style='font-family:"Courier New"'><o:p></o:p></span></font></p>
<p style='margin:0cm;margin-bottom:.0001pt'><font size=2 color=navy face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New"; color:navy'></RESULT></span></font><font face="Courier New"><span style='font-family:"Courier New"'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=blue face=Arial><span lang=EN-US style='font-size:10.0pt;font-family:Arial;color:blue'><o:p> </o:p></span>< /font></p>
<p class=MsoNormal><font size=2 color=blue face=Arial><span lang=EN-US style='font-size:10.0pt;font-family:Arial;color:blue'>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:<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New"'><--! Coy input node to the output --><br> <xsl:template match="*"><o:p></o:p></span></font></p>
<p class=MsoNormal style='text-indent:35.4pt'><font size=2 face="Courier New"> <span lang=EN-US style='font-size:10.0pt;font-family:"Courier New"'><xsl:copy> <o:p></o:p></span></font></p>
<p class=MsoNormal style='margin-left:35.4pt;text-indent:35.4pt'><font size=2 face="Courier New"><span lang=EN-US style='font-size:10.0pt;font-family: "Courier New"'><xsl:apply-templates /><o:p></o:p></span></font></p>
<p class=MsoNormal style='margin-left:35.4pt'><font size=2 face="Courier New"> <span lang=EN-US style='font-size:10.0pt;font-family:"Courier New"'></xsl:copy> <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New"'></xsl:template><o:p>< /o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New"'><xsl:template match="OUTPUT"></xsl:template> <!--Output node is not copied to output --><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New"'><--! Copy output nodes to Parameters element --><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New"'><xsl:template match="/RESULT/PARAMETERS"><o:p></o:p></span></font></p>
<p class=MsoNormal style='text-indent:35.4pt'><font size=2 face="Courier New"> <span lang=EN-US style='font-size:10.0pt;font-family:"Courier New"'><xsl:copy> <o:p></o:p></span></font></p>
<p class=MsoNormal style='margin-left:35.4pt;text-indent:35.4pt'><font size=2 face="Courier New"><span lang=EN-US style='font-size:10.0pt;font-family: "Courier New"'><xsl:copy-of select="/RESULT/OUTPUT/*" /><o:p></o:p></span></font></p>
<p class=MsoNormal style='margin-left:35.4pt;text-indent:35.4pt'><font size=2 face="Courier New"><span lang=EN-US style='font-size:10.0pt;font-family: "Courier New"'><xsl:apply-templates /><o:p></o:p></span></font></p>
<p class=MsoNormal style='text-indent:35.4pt'><font size=2 face="Courier New"> <span lang=EN-US style='font-size:10.0pt;font-family:"Courier New"'><xsl:copy> <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face="Courier New"><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New"'></xsl:template><o:p>< /o:p></span></font></p>
<p class=MsoNormal><font size=2 color=blue face=Arial><span lang=EN-US style='font-size:10.0pt;font-family:Arial;color:blue'><o:p> </o:p></span>< /font></p>
<p class=MsoNormal><font size=2 color=blue face=Arial><span lang=EN-US style='font-size:10.0pt;font-family:Arial;color:blue'>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:<o:p></o:p></span></font></p>
<p style='margin:0cm;margin-bottom:.0001pt'><font size=2 color=navy face="Courier New"><span lang=EN-US style='font-size:10.0pt;font-family: "Courier New"; color:navy'><RESULT></span></font><font face="Courier New"><span style='font-family:"Courier New"'><o:p></o:p></span></font></p>
<p style='margin:0cm;margin-bottom:.0001pt'><font size=2 color=navy face="Courier New"><span lang=EN-US style='font-size:10.0pt;font-family: "Courier New"; color:navy'> <PARAMETERS></span></font><font face="Courier New"> <span style='font-family:"Courier New"'><o:p></o:p></span></font></p>
<p style='margin:0cm;margin-bottom:.0001pt'><font size=2 color=navy face="Courier New"><span lang=EN-US style='font-size:10.0pt;font-family: "Courier New"; color:navy'> <CYCLE></span></font><font face="Courier New"><span style='font-family:"Courier New"'><o:p></o:p></span>< /font></p>
<p style='margin:0cm;margin-bottom:.0001pt'><font size=2 color=navy face="Courier New"><span lang=EN-US style='font-size:10.0pt;font-family: "Courier New"; color:navy'> <ENDDATE>20060215</ENDDATE></span></font><font face="Courier New"> <span style='font-family:"Courier New"'><o:p></o:p></span></font></p>
<p style='margin:0cm;margin-bottom:.0001pt'><font size=2 color=navy face="Courier New"><span lang=EN-US style='font-size:10.0pt;font-family: "Courier New"; color:navy'> </CYCLE><o:p></o:p></span></font></p>
<p style='margin:0cm;margin-bottom:.0001pt'><b><font size=2 color=navy face="Courier New"><span lang=EN-US style='font-size:10.0pt;font-family: "Courier New"; color:navy;font-weight:bold'> <FILE>b</FILE></span>< /font></b><font face="Courier New"><span style='font-family:"Courier New"'><o:p></o:p></span>< /font></p>
<p style='margin:0cm;margin-bottom:.0001pt'><b><font size=2 color=navy face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New"; color:navy;font-weight:bold'> <FILENAME>E:\ftphome\vodafone <wbr>\xml\CC20060215S50.XML<<wbr>/FILENAME></span></font></b><font face="Courier New"><span style='font-family:"Courier New"'><o:p></o:p></span>< /font></p>
<p style='margin:0cm;margin-bottom:.0001pt'><font size=2 color=navy face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New"; color:navy'> </PARAMETERS></span></font><font face="Courier New"> <span style='font-family:"Courier New"'><o:p></o:p></span></font></p>
<p style='margin:0cm;margin-bottom:.0001pt'><font size=2 color=navy face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New"; color:navy'></RESULT></span></font><font face="Courier New"><span style='font-family:"Courier New"'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=blue face=Arial><span lang=EN-US style='font-size:10.0pt;font-family:Arial;color:blue'><o:p> </o:p></span>< /font></p>
<p class=MsoNormal><font size=2 color=blue face=Arial><span lang=EN-US style='font-size:10.0pt;font-family:Arial;color:blue'>I would much appreciate some help, and since I’m not sure I’m using the right mailing list, please accept my apologies and please guide to a correct one.<o:p></o:p></span> </font></p>
<p class=MsoNormal><font size=2 color=blue face=Arial><span lang=EN-US style='font-size:10.0pt;font-family:Arial;color:blue'><o:p> </o:p></span>< /font></p>
<p class=MsoNormal><font size=2 color=blue face=Arial><span lang=EN-US style='font-size:10.0pt;font-family:Arial;color:blue'>Many many thanks<o:p></o :p></span></font></p>
<p class=MsoNormal><font size=2 color=blue face=Arial><span lang=EN-US style='font-size:10.0pt;font-family:Arial;color:blue'>Higino Silva<o:p></o:p>< /span></font></p>
</div>
<p> </p><p class=MsoPlainText><font size=1 color=#999999 face=Arial><span lang=PT style='font-size:7.5pt;font-family:Arial;color:#999999;mso-ansi -language:PT'>AVISO<p></p>Esta mensagem e quaisquer anexos seus podem conter informação confidencial para uso exclusivo do destinat ário. Cabe ao destinatário assegurar a verificação de vírus e outras medidas que assegurem que esta mensagem nã ;o afecta os seus sistemas. Se não for o destinatário, não deverá usar, distribuir ou copiar este e-mail, devendo proceder à sua eliminação e informar o emissor. É estritamente proibido o uso, a distribuição, a cópia ou qualquer forma de disseminação não autorizada deste e-mail e seus anexos. Obrigado.</span></font></p><p> </p><p class=MsoPlainText><font size=1 color=#999999 face=Arial><span lang=EN style='font-size:7.5pt;font-family:Arial ;color:#999999;mso-ansi-language:EN'>DISCLAIMER<p></p>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.</span>< /font></p></body>
</html>
|
|
 |