Re: [xsl] Variables in XSLT

Subject: Re: [xsl] Variables in XSLT
From: "Paul Delange" <Paul.Delange@xxxxxxx>
Date: Fri, 27 Jan 2006 12:04:12 -0500
Thanks for your response. I assure you in several other languages I'm
awesome and will eventually reach that with XSLT - someday. But for now ;o)

EFFDT is not a global variable nor is it in a higher level of the XML. So,
is it that case that in my <xsl:template match="VENDOR_LOC"> I'd need to
set an $effdt variable by selecting the maximum of the different <EFFDT>
values below (is that possible?), then do a subsequent <xsl:template
match="VNDR_URL"> in which;

<xsl:if test="EFFDT = '$effdt'">
   <HOMEPAGE><xsl:value-of select="VNDR_URL/URL" /></HOMEPAGE>

-----------------

        <VNDR_LOC_SCROL class="R">
          <VENDOR_LOC class="R">
            <VNDR_LOC IsChanged="Y">1</VNDR_LOC>
            <VNDR_URL class="R">
              <EFFDT IsChanged="Y">2006-01-26</EFFDT>
              <LINE_NBR IsChanged="Y">1</LINE_NBR>
              <URL IsChanged="Y">www.this_is_the_desired_url.com</URL>
            </VNDR_URL>
            <VNDR_URL class="R">
              <EFFDT IsChanged="Y">2006-01-26</EFFDT>
              <LINE_NBR IsChanged="Y">2</LINE_NBR>
              <URL IsChanged="Y">www.this_is_an_unwanted_url.com</URL>
            </VNDR_URL>
          </VENDOR_LOC>
          <VENDOR_LOC class="R">
            <VNDR_LOC IsChanged="Y">1</VNDR_LOC>
            <VNDR_URL class="R">
              <EFFDT IsChanged="Y">1901-01-01</EFFDT>
              <LINE_NBR IsChanged="Y">1</LINE_NBR>
              <URL IsChanged="Y">www.this_is_another_unwanted_url.com</URL>
            </VNDR_URL>
          </VENDOR_LOC>
        </VNDR_LOC_SCROL>
---------

<xsl:template match="VENDOR_LOC">
   <xsl:if test="VNDR_LOC = ../../DEFAULT_LOC">
      <C3><xsl:value-of select="VNDR_LOC" /></C3>
      <HOMEPAGE><xsl:value-of select="VNDR_URL/URL" /></HOMEPAGE>
   </xsl:if>
</xsl:template>




                                                                                                                                       
                      David Carlisle                                                                                                   
                      <davidc@xxxxxxxxx        To:       xsl-list@xxxxxxxxxxxxxxxxxxxxxx                                               
                      >                        cc:                                                                                     
                                               Subject:  Re: [xsl] Variables in XSLT                                                   
                      01/27/2006 10:54                                                                                                 
                      AM                                                                                                               
                      Please respond to                                                                                                
                      xsl-list                                                                                                         
                                                                                                                                       
                                                                                                                                       





  With my conventional programming background, I want to define a $maxeffdt
  variable BEFORE I call the template below and this do some kind of
<xsl:if
  test="EFFDT = $maxeffdt> but I'm not sure this is doable/appropriate in
the
  new XSLT world.

You have two options if $maxeffdt is a global parameter
set by
<xsl:param name="maxeffdt"/>
at the top level of your stylesheet and passed in (in a system-dependant
manner) when you start the program then it's globally available and you
can reference it directly in your template.

If it is set within the template (eg if it is a value from some other
element in the source document) then it;s a local parameter so you need
to declare it in this template and pass it in.

<xsl:template match="VENDOR_LOC">
  <xsl:param name="maxeffdt"/>


then call it as

  <xsl:apply-templates select="VENDOR_LOC">
    <xsl:with-param name="maxeffdt" select="....something

Once you have your two dates the problem is comparing them. XSLT1
doesn't have string or date comparison operators (XSLT2 will have both)
so the easiest thing is to get rid of the - and compare as numbers
<xsl:if test="translate($maxeffdt,'-','') &lt; translate(EFFDT,'-','')">
 ...

so this compares 2006-01-26 against 1901-01-01 by comparing
 20060126  19010101

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

Current Thread