RE: Urgent..please advise

Subject: RE: Urgent..please advise
From: "Maxime Levesque" <maximel@xxxxxxxxxxxxxx>
Date: Mon, 26 Jul 1999 10:14:48 -0700
 
Try the stylesheet below,
 
I didn't execute it so you might have to debug it a little !
But the concepts are shown ...
 
 
you might also try to extract the variables this way :
    <xsl:variable name='y' expr='string(./YEAR)'/>
 
 
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/XSL/Transform/1.0">
 

    <xsl:template match="//DATETIME[@QUALIFIER='CREATION']">
 
    <xsl:variable name='y' expr='./YEAR/text()'/>
    <xsl:variable name='m' expr='./DAY/text()'/>
    <xsl:variable name='d' expr='./DAY/text()'/>
    <xsl:variable name='h' expr='./HOUR/text()'/>
    <xsl:variable name='min' expr='./MINUTE/text()'/>
    <xsl:variable name='sec' expr='./SECOND/text()'/>
<!--
    <xsl:variable name='subsec' expr='./SUBSECOND/text()'/>
     <xsl:variable name='subsec' expr='./TIMEZONE/text()'/>
    <xsl:variable name='tz' expr='./TIMEZONE/text()'/>
-->
 
    <CREATION_DATE><xsl:value-of select='$y'/>/<xsl:value-of select='$m'/>/<xsl:value-of select='$d'/> 
       <xsl:value-of select='$h'/>:<xsl:value-of select='$min'/>:<xsl:value-of select='$sec'/>
    <CREATION_DATE>
 
   </xsl:template>
 
 
 
  <!-- A template that copies "as is", that's what will leave the rest of the tree unchanged :
    notice that a priority of -1 is assigned, since if conflicts with the template above, and
    we want this one to have lesser priority ...
   -->
 
  <xsl:template match="*|@*|comment()|pi()|text()" priority="-1" name="identity">
    <xsl:copy>
      <xsl:apply-templates select="*|@*|comment()|pi()|text()"/>
    </xsl:copy>
  </xsl:template>
 
</xsl:stylesheet>
 
 
 
If you want to deal with other 'qualifiers' you can do :
 
 
    <xsl:template match="//DATETIME">
 
      <xsl:variable name='qualifier' expr='@QUALIFIER'/>
 
      <xsl:chose>
         <xsl:when test='$qualifier="CREATION"'>
                do something
      </xsl:when>
         <xsl:when test='$qualifier="SOMETHING_ELSE"'>
                 do something else ...
      </xsl:when>
    </xsl:chose>
 
 
 
 Maxime Levesque
 
-----Original Mes  sage-----
From: owner-xsl-list@xxxxxxxxxxxxxxxx [mailto:owner-xsl-list@xxxxxxxxxxxxxxxx]On Behalf Of Charles Fong
Sent: Monday, July 26, 1999 1:00 AM
To: XSL-List@xxxxxxxxxxxxxxxx
Cc: cfong@xxxxxxxxxxxxx
Subject: Urgent..please advise
Importance: High

Hi, experts,
      I am trying to do some XSLT stuffs and have such problem to solve.

This is a part of the source xml file.

  <CNTROLAREA>
  <SENDER>
  <LOGICALID>XX141HG09</LOGICALID>
  <COMPONENT>PUR</COMPONENT>
  <TASK>MAINT</TASK>
  <REFERENCEID>95129945823449</REFERENCEID>
  <CONFIRMATION>1</CONFIRMATION>
  <LANGUAGE>EN</LANGUAGE>
  <CODEPAGE>test</CODEPAGE>
  <AUTHID>CMKURT</AUTHID>
  </SENDER>
  <DATETIME qualifier="CREATION">
  <YEAR>1998</YEAR>
  <MONTH>11</MONTH>
  <DAY>21</DAY>
  <HOUR>17</HOUR>
  <MINUTE>11</MINUTE>
  <SECOND>45</SECOND>
  <SUBSECOND>0000</SUBSECOND>
  <TIMEZONE>-0600</TIMEZONE>
  </DATETIME>
  </CNTROLAREA>

I am still trying to figure out a xsl file  which can  produce the following
resulting  xml:

<CNTROLAREA>
  <SENDER>
  <LOGICALID>XX141HG09</LOGICALID>
  <COMPONENT>PUR</COMPONENT>
  <TASK>MAINT</TASK>
  <REFERENCEID>95129945823449</REFERENCEID>
  <CONFIRMATION>1</CONFIRMATION>
  <LANGUAGE>EN</LANGUAGE>
  <CODEPAGE>test</CODEPAGE>
  <AUTHID>CMKURT</AUTHID>
  </SENDER>
  <CREATION_DATE>1998/11/21 17:11:45</CREATION_DATE>
 </CNTROLAREA>

Basically, I want to try to identify the DATETIME structure in the source
xml file and collapse the structure to a simple data structure depending on
the "qualifier" value of the DATETIME as shown above. All the other xml
is untouched and need to appear in the resulting xml. Also this DATETIME structure
can appear at any level of the tree in the source xml (above only a simple example).

So my questions is : How can I achieve this in XSLT? i.e.  extracting the
DATETIME structure at whatever level from the source xml and collapsing it
as shown above with all other xml untouched in the source.  If this can be done,
could you kindly provide me the xsl command to do it? Thanks a lot in advance.

charles
 
 

Current Thread