Subjects
Home
Xalan extension functions
Fomatting question serializing DOM with pretty print
xalan with pull parser
Cannot find the declaration
Apache Xalan drop support to run on JRE 1 1 x
Why does Doctype change processing of a document
Node set to XML string via Java extensions in Xalan J: possible?
Templates/Transformers + thread safety???
Problem evaluating xpath with muliple prefix with different namespace
remove an arbitrary attribute from xsl output
Xalan3 XSLT 2 0 XPath 2 0 support?
Problem using compiled translets with Xalan !!
Xalan and jstl 1 1 problem with transform tag
NullPointer in DOM2DTM getLocalName
URIResolvers base parameter with xsltc and cascaded imports
Performance problem for Xalan J on intel dual core
Standard libraries in JAXP?
Serializing a DOM tree to XML file, customize entities replacement
Library Conflict Involving BCEL Library
A question on how users are using <xsl:message >
Kevin Cormier as a new Apache Xalan J committer
Struggling to iterate over tokenized string
Xalan count() trouble
Problem with recursive xpath
Error when switching to java 1 5
document( ' ')
Problem with Xalan2 7 0 transformation
cr/lf options
entity encoded XML
can xalan transform 2 xml using one xslt?
Xalan J JIRA defect review Monday October 16, 2006 from 2:00 to 3:30 pm ED
xsl transform with cdata section elements
xslt parameters not expanded
Weird behavior of XPath evaluate()
How to avoid <xsl:message > instruction prints stylesheet file informations ?
Cannot find SimpleTransform subdirectory after installing Xalan J
recover from document not found exceptions
jdk1 5 and Xalan jar differences?
Performance Issue
Error/Bug adding floating point numbers
XPathAPI: eval exp using nodes with default namespace
modifying xalan to output invalid XML
NullPointerException
mege two separate xml nodes into one
Is this a XALAN document identification bug?
is StylesheetRoot really java io Serializable ?
transform() fails for DOMSource but succeeds for StreamSource
Thoughts on Transformer parameter passing
HELP, Xalan and jstl 1 1 problem with transformer
Problem with XPath namespace axis?
string utils:replace deleting search string if replacement string is an HTML
help with enumeration values pls
xalan 2 5 1 vs 2 7 performance question
How to insert/update in XML document
HTML Serialization and Handling of Ampersands in HREF Attributes
XHTML link tag stripping
SystemId Unknown; Line #24; Column #49; java lang NullPointerException
xpath text() help
Apostrophe problem with xalan 2 7 0
How to set variables in XML document?
Links
Home
Oracle database error code ...
 
Search:  
Power your search with and, or, +, -, or "some phrase" operators.
Conditional statements in XSLT

Conditional statements in XSLT

2006-03-24       - By Higino Silva
Reply:     1     2  

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>&nbsp;</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&#8217;m using Xalan J,
and though I don&#8217;t have a particular problem with the implementation of
Xalan I&#8217;m having troubles implementing one of the requirements for our
project, &nbsp;I&#8217;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'>&nbsp;<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'>&lt;RESULT&gt;</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'>&nbsp; &lt;PARAMETERS&gt;</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'>&nbsp;&nbsp;&nbsp; &lt;CYCLE&gt;</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'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;ENDDATE&gt;20060215&lt;/ENDDATE&gt;</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'>&nbsp;&nbsp;&nbsp; &lt;/CYCLE&gt;<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'>&nbsp;&nbsp;&nbsp; &lt;FILE&gt;&lt;CHECK/&gt;&lt;/FILE&gt;</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'>&nbsp; &lt;/PARAMETERS&gt;<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'>&nbsp; &lt;OUTPUT&gt;</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'>&nbsp;&nbsp; &nbsp;&lt;FILE&gt;b&lt;/FILE&gt;</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'>&nbsp;&nbsp; &nbsp;&lt;FILENAME&gt;E:\ftphome\vodafone<wbr>\xml
\CC20060215S50.XML&lt;<wbr>/FILENAME&gt;<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'>&nbsp; &lt;/OUTPUT&gt;</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'>&lt;/RESULT&gt;</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>&nbsp;</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"'>&lt;--! Coy input node to
the output --&gt;<br>
&lt;xsl:template match=&quot;*&quot;&gt;<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"'>&lt;xsl:copy&gt;
<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"'>&lt;xsl:apply-templates
/&gt;<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"'>&lt;/xsl:copy&gt;
<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"'>&lt;/xsl:template&gt;<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"'>&lt;xsl:template
match=&quot;OUTPUT&quot;&gt;&lt;/xsl:template&gt; &lt;!--Output node is not
copied
to output --&gt;<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"'>&lt;--! Copy output nodes to
Parameters element --&gt;<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"'>&lt;xsl:template
match=&quot;/RESULT/PARAMETERS&quot;&gt;<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"'>&lt;xsl:copy&gt;
<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"'>&lt;xsl:copy-of
select=&quot;/RESULT/OUTPUT/*&quot; /&gt;<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"'>&lt;xsl:apply-templates
/&gt;<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"'>&lt;xsl:copy&gt;
<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"'>&lt;/xsl:template&gt;<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>&nbsp;</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'>&lt;RESULT&gt;</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'>&nbsp; &lt;PARAMETERS&gt;</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'>&nbsp;&nbsp;&nbsp; &lt;CYCLE&gt;</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'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;ENDDATE&gt;20060215&lt;/ENDDATE&gt;</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'>&nbsp;&nbsp;&nbsp; &lt;/CYCLE&gt;<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'>&nbsp;&nbsp; &lt;FILE&gt;b&lt;/FILE&gt;</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'>&nbsp;&nbsp; &lt;FILENAME&gt;E:\ftphome\vodafone
<wbr>\xml\CC20060215S50.XML&lt;<wbr>/FILENAME&gt;</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'>&nbsp; &lt;/PARAMETERS&gt;</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'>&lt;/RESULT&gt;</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>&nbsp;</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&#8217;m not sure I&#8217;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>&nbsp;</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>&nbsp;</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&nbsp;podem
conter informa&ccedil;&atilde;o confidencial para uso exclusivo do destinat
&aacute;rio. Cabe ao destinat&aacute;rio assegurar a verifica&ccedil;&atilde;o
de v&iacute;rus e outras medidas&nbsp;que assegurem que esta mensagem n&atilde
;o afecta os seus sistemas. Se n&atilde;o for o destinat&aacute;rio, n&atilde;o
dever&aacute; usar, distribuir ou copiar este e-mail, devendo proceder &agrave;
&nbsp;sua elimina&ccedil;&atilde;o e informar o emissor. &Eacute; estritamente
proibido o uso, a distribui&ccedil;&atilde;o, a c&oacute;pia ou qualquer forma
de dissemina&ccedil;&atilde;o n&atilde;o autorizada deste e-mail e seus anexos.
Obrigado.</span></font></p><p>&nbsp;</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>