XSLT Output - blank attributes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • requeth@gmail.com

    XSLT Output - blank attributes

    Allo,

    I'm somewhat new to XSLT but I am doing fairly well. I just got stuck
    on one item. I have created a XSL stylesheet to pull information from
    an XML file and generate a report. I would like to add functionality
    for missing data, in which if the attribute contains nothing ("") then
    the field is red. I added in a choose function which flags it red, but
    only if the attribute itself was not populated into the source file. Is
    there a way to flag both if the attribute has not populated and if it
    is just a blank attribute (""). If you know the answer to this, is
    there a term for just "" that I could search more on?

    Thanks

  • Joe Kesselman

    #2
    Re: XSLT Output - blank attributes

    requeth@gmail.c om wrote:[color=blue]
    > there a way to flag both if the attribute has not populated and if it
    > is just a blank attribute ("")[/color]

    First thought that occurs to me is string(@youratt ribute)="", which
    should be true for either case.
    [color=blue]
    >is there a term for just ""[/color]

    The most commonly used term is "empty string".

    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry

    Comment

    • requeth@gmail.com

      #3
      Re: XSLT Output - blank attributes

      I tried this, and looking around for information on the w3
      recommendation and others. I add the string and nothing is changed. The
      field will not populate in my output table at all if it is an empty
      string. If I have any character, or no attribute in the file at all, it
      flags red as I wish. I have attached what my origional code was, and
      what I changed it to. I have tried many things to get this to work, but
      as I said I'm fairly new to this.

      <xsl:choose>
      <xsl:when
      test="CMS274201 00_2000C/CMS27420300_210 0CA/CMS27420300_210 0CA_NM1_Provide rName/@CMS27420300_21 00CA_NM103_Prov iderLastOrOrgan izationName
      != 0">
      <td>
      <xsl:value-of
      select="CMS2742 0100_2000C/CMS27420300_210 0CA/CMS27420300_210 0CA_NM1_Provide rName/@CMS27420300_21 00CA_NM103_Prov iderLastOrOrgan izationName"/>
      </td>
      </xsl:when>
      <xsl:otherwis e>
      <td bgcolor="RED"> </td>
      </xsl:otherwise>
      ---------------------------

      <xsl:choose>
      <xsl:when
      test="string(CM S27420100_2000C/CMS27420300_210 0CA/CMS27420300_210 0CA_NM1_Provide rName/@CMS27420300_21 00CA_NM103_Prov iderLastOrOrgan izationName)
      != 0">
      <td>
      <xsl:value-of

      select="CMS2742 0100_2000C/CMS27420300_210 0CA/CMS27420300_210 0CA_NM1_Provide rName/@CMS27420300_21 00CA_NM103_Prov iderLastOrOrgan izationName"
      />
      </td>
      </xsl:when>
      <xsl:otherwis e>
      <td bgcolor="RED"> </td>
      </xsl:otherwise>
      Thanks

      Joe Kesselman wrote:[color=blue]
      > requeth@gmail.c om wrote:[color=green]
      > > there a way to flag both if the attribute has not populated and if it
      > > is just a blank attribute ("")[/color]
      >
      > First thought that occurs to me is string(@youratt ribute)="", which
      > should be true for either case.
      >[color=green]
      > >is there a term for just ""[/color]
      >
      > The most commonly used term is "empty string".
      >
      > --
      > () ASCII Ribbon Campaign | Joe Kesselman
      > /\ Stamp out HTML e-mail! | System architexture and kinetic poetry[/color]

      Comment

      • A. Bolmarcich

        #4
        Re: XSLT Output - blank attributes

        On 2006-06-30, requeth@gmail.c om <requeth@gmail. com> wrote:[color=blue]
        > I tried this, and looking around for information on the w3
        > recommendation and others. I add the string and nothing is changed. The
        > field will not populate in my output table at all if it is an empty
        > string. If I have any character, or no attribute in the file at all, it
        > flags red as I wish. I have attached what my origional code was, and
        > what I changed it to. I have tried many things to get this to work, but
        > as I said I'm fairly new to this.
        >
        ><xsl:choose>
        > <xsl:when
        > test="CMS274201 00_2000C/CMS27420300_210 0CA/CMS27420300_210 0CA_NM1_Provide rName/@CMS27420300_21 00CA_NM103_Prov iderLastOrOrgan izationName
        > != 0">[/color]

        The "!= 0" comparison is false only when the attribute value is "0" (or
        some other value that when converted to a number has a value of 0). The
        comparison is true when the attribute is not present and when the
        attribute has an empty value. Perhaps, you want to use something like

        <xsl:test="stri ng(...)">

        where the "..." is your XPATH expression.
        [color=blue]
        > <td>
        > <xsl:value-of
        > select="CMS2742 0100_2000C/CMS27420300_210 0CA/CMS27420300_210 0CA_NM1_Provide rName/@CMS27420300_21 00CA_NM103_Prov iderLastOrOrgan izationName"/>
        > </td>
        > </xsl:when>
        > <xsl:otherwis e>
        > <td bgcolor="RED"> </td>
        > </xsl:otherwise>
        > ---------------------------
        >
        ><xsl:choose>
        > <xsl:when
        > test="string(CM S27420100_2000C/CMS27420300_210 0CA/CMS27420300_210 0CA_NM1_Provide rName/@CMS27420300_21 00CA_NM103_Prov iderLastOrOrgan izationName)
        > != 0">
        > <td>
        > <xsl:value-of
        >
        > select="CMS2742 0100_2000C/CMS27420300_210 0CA/CMS27420300_210 0CA_NM1_Provide rName/@CMS27420300_21 00CA_NM103_Prov iderLastOrOrgan izationName"
        > />
        > </td>
        > </xsl:when>
        > <xsl:otherwis e>
        > <td bgcolor="RED"> </td>
        > </xsl:otherwise>[/color]

        Comment

        • requeth@gmail.com

          #5
          Re: XSLT Output - blank attributes

          This is why I add the I'm an idiot explanations to posts. I had tried
          this without the string expression but forgot to try it with it
          included. That worked, thanks.

          A. Bolmarcich wrote:[color=blue]
          > On 2006-06-30, requeth@gmail.c om <requeth@gmail. com> wrote:[color=green]
          > > I tried this, and looking around for information on the w3
          > > recommendation and others. I add the string and nothing is changed. The
          > > field will not populate in my output table at all if it is an empty
          > > string. If I have any character, or no attribute in the file at all, it
          > > flags red as I wish. I have attached what my origional code was, and
          > > what I changed it to. I have tried many things to get this to work, but
          > > as I said I'm fairly new to this.
          > >
          > ><xsl:choose>
          > > <xsl:when
          > > test="CMS274201 00_2000C/CMS27420300_210 0CA/CMS27420300_210 0CA_NM1_Provide rName/@CMS27420300_21 00CA_NM103_Prov iderLastOrOrgan izationName
          > > != 0">[/color]
          >
          > The "!= 0" comparison is false only when the attribute value is "0" (or
          > some other value that when converted to a number has a value of 0). The
          > comparison is true when the attribute is not present and when the
          > attribute has an empty value. Perhaps, you want to use something like
          >
          > <xsl:test="stri ng(...)">
          >
          > where the "..." is your XPATH expression.
          >[color=green]
          > > <td>
          > > <xsl:value-of
          > > select="CMS2742 0100_2000C/CMS27420300_210 0CA/CMS27420300_210 0CA_NM1_Provide rName/@CMS27420300_21 00CA_NM103_Prov iderLastOrOrgan izationName"/>
          > > </td>
          > > </xsl:when>
          > > <xsl:otherwis e>
          > > <td bgcolor="RED"> </td>
          > > </xsl:otherwise>
          > > ---------------------------
          > >
          > ><xsl:choose>
          > > <xsl:when
          > > test="string(CM S27420100_2000C/CMS27420300_210 0CA/CMS27420300_210 0CA_NM1_Provide rName/@CMS27420300_21 00CA_NM103_Prov iderLastOrOrgan izationName)
          > > != 0">
          > > <td>
          > > <xsl:value-of
          > >
          > > select="CMS2742 0100_2000C/CMS27420300_210 0CA/CMS27420300_210 0CA_NM1_Provide rName/@CMS27420300_21 00CA_NM103_Prov iderLastOrOrgan izationName"
          > > />
          > > </td>
          > > </xsl:when>
          > > <xsl:otherwis e>
          > > <td bgcolor="RED"> </td>
          > > </xsl:otherwise>[/color][/color]

          Comment

          • Peter Flynn

            #6
            Re: XSLT Output - blank attributes

            requeth@gmail.c om wrote:
            Allo,
            >
            I'm somewhat new to XSLT but I am doing fairly well. I just got stuck
            on one item. I have created a XSL stylesheet to pull information from
            an XML file and generate a report. I would like to add functionality
            for missing data, in which if the attribute contains nothing ("") then
            the field is red. I added in a choose function which flags it red, but
            only if the attribute itself was not populated into the source file. Is
            there a way to flag both if the attribute has not populated and if it
            is just a blank attribute (""). If you know the answer to this, is
            there a term for just "" that I could search more on?
            There may be more than presence or absence at work here.

            If the DTD or Schema defines a default value for the attribute,
            then the processor will behave as though the attribute was
            specified with that value, even if it's physically absent from
            the document.

            <xsl:if test="@foo=''"w ill only be true if
            (a) foo="" is actually in the document, or
            (b) the null string is declared as the default value

            <xsl:if test="@foo"will only be true if
            (a) foo="" or foo="something" is actually in the document, or
            (b) foo is declared with a default value (of any kind)

            ///Peter
            --
            XML FAQ: http://xml.silmaril.ie/

            Comment

            Working...