Loading ...
Sorry, an error occurred while loading the content.

Re: [XSL-FO] how to use substing and conditional selection in xsl

Expand Messages
  • John E. Simpson
    [As an aside, I think it s best to post questions like this one -- regarding the transformation of XML to (X)HTML, rather than to XSL-FO -- to the XSL-L,
    Message 1 of 2 , Jun 25, 2001
    • 0 Attachment
      [As an aside, I think it's best to post questions like this one --
      regarding the transformation of XML to (X)HTML, rather than to XSL-FO -- to
      the XSL-L, XHTML-L, or XML-L mailing lists. You'd probably get more replies
      that way. :)]

      At 06:34 PM 06/25/2001 +0000, PANDUR_K_PRASANNA@... wrote:
      >i found that conditional selection work fine when i put namespace as
      ><xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
      >I also found that the substring function works fine with this
      ><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

      As a starting point, you should stop using the first namespace declaration
      above (the one which ends "WD-xsl"). It was useful as an interim,
      Microsoft-supported namespace, but not even Microsoft recommends its
      continued use. Also, your xsl:stylesheet element needs a version="1.0"

      >I want both substring selection and conditional selection to
      >be done in same style sheet.How can I achieve this?

      If I understand correctly, you want to do *something* like the following:

      <!-- Get all ADDRESS children of the NAME child(ren) of the
      current node, as long as the ADDRESS elements' StartTime attributes
      indicate a date later than 04/26/2001 and their EndTime attributes
      indicate a date earlier than or equal to 05/27/2001. -->
      select="NAME/ADDRESS[@StartTime > '04/26/2001' and
      @EndTime <= '05/27/2001']">
      <!-- Transfer to the result tree the value of the StartTime
      attribute's first 10 characters (i.e., just the date) -->
      <xsl:value-of select="substring(@StartTime,1,10)"/>

      Is that right?

      If so, first a couple of housekeeping things:

      (1) The code fragments included in your message lacked proper punctuation
      -- the double quotes around the full value of the select attributes. I'm
      assuming this was just a typo or copy-and-paste error; if not, it's easily

      (2) A much bigger problem, perhaps even insurmountable, is the apparent
      assumption in your code that XML/XSLT has an inherent awareness of date
      data types. That's not so. The only data types you can handle in an XSLT
      stylesheet are string, number, Boolean, and result-tree fragment (RTF).
      Testing for some value > '04/26/2001', for example, simply selects that
      value if AS A STRING (lexically) it exceeds that test string. So
      '05/31/1900' is a "greater" string value than '04/26/2001', even though as
      a date value it's "smaller." If you really need to test dates, your
      StartTime and EndTime attributes will need to use a date/time format which
      works AS A STRING, not just AS A DATE. For instance:
      <ADDRESS StartTime="2001/04/27 13:04:35">...</ADDRESS>
      or some such.

      Okay, now, suppose the source document looks like this:

      <!-- Skipped - EndTime too late -->
      StartTime="2001/04/27 13:04:35"
      EndTime="2001/06/22 01:02:03"/>
      <!-- Skipped - StartTime too soon -->
      StartTime="2001/02/27 13:04:35"
      EndTime="2001/06/22 01:02:03"/>
      <!-- Skipped - StartTime too soon and EndTime too late -->
      StartTime="2001/01/27 13:04:35"
      EndTime="2001/07/22 01:02:03"/>
      <!-- Just right :) -->
      StartTime="2001/04/27 13:04:35"
      EndTime="2001/05/01 01:02:03"/>

      Start out with a stylesheet that does no selection by predicate at all
      (xsl:stylesheet omitted):

      <xsl:template match="root">
      <xsl:value-of select="substring(@StartTime,1,10)"/>

      This produces the expected output -- one row and td element for each
      ADDRESS element.

      This should put you a good way toward the solution.

      >I did try out including both namespaces in a single xsl and
      >implenting the substring and conditional statements, but it does not

      No, it doesn't. :)

      John E. Simpson | "I just got out of the hospital. I was in a
      http://www.flixml.org | speed reading accident. I hit a bookmark and
      XML Q&A: www.xml.com | flew across the room." (Steven Wright)
    Your message has been successfully submitted and would be delivered to recipients shortly.