XSLT Output - blank attributes

Discussion in 'XML' started by requeth@gmail.com, Jun 29, 2006.

  1. Guest

    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
     
    , Jun 29, 2006
    #1
    1. Advertising

  2. wrote:
    > there a way to flag both if the attribute has not populated and if it
    > is just a blank attribute ("")


    First thought that occurs to me is string(@yourattribute)="", which
    should be true for either case.

    >is there a term for just ""


    The most commonly used term is "empty string".

    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry
     
    Joe Kesselman, Jun 30, 2006
    #2
    1. Advertising

  3. Guest

    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="CMS27420100_2000C/CMS27420300_2100CA/CMS27420300_2100CA_NM1_ProviderName/@CMS27420300_2100CA_NM103_ProviderLastOrOrganizationName
    != 0">
    <td>
    <xsl:value-of
    select="CMS27420100_2000C/CMS27420300_2100CA/CMS27420300_2100CA_NM1_ProviderName/@CMS27420300_2100CA_NM103_ProviderLastOrOrganizationName"/>
    </td>
    </xsl:when>
    <xsl:eek:therwise>
    <td bgcolor="RED"> </td>
    </xsl:eek:therwise>
    ---------------------------

    <xsl:choose>
    <xsl:when
    test="string(CMS27420100_2000C/CMS27420300_2100CA/CMS27420300_2100CA_NM1_ProviderName/@CMS27420300_2100CA_NM103_ProviderLastOrOrganizationName)
    != 0">
    <td>
    <xsl:value-of

    select="CMS27420100_2000C/CMS27420300_2100CA/CMS27420300_2100CA_NM1_ProviderName/@CMS27420300_2100CA_NM103_ProviderLastOrOrganizationName"
    />
    </td>
    </xsl:when>
    <xsl:eek:therwise>
    <td bgcolor="RED"> </td>
    </xsl:eek:therwise>
    Thanks

    Joe Kesselman wrote:
    > wrote:
    > > there a way to flag both if the attribute has not populated and if it
    > > is just a blank attribute ("")

    >
    > First thought that occurs to me is string(@yourattribute)="", which
    > should be true for either case.
    >
    > >is there a term for just ""

    >
    > The most commonly used term is "empty string".
    >
    > --
    > () ASCII Ribbon Campaign | Joe Kesselman
    > /\ Stamp out HTML e-mail! | System architexture and kinetic poetry
     
    , Jun 30, 2006
    #3
  4. On 2006-06-30, <> wrote:
    > 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="CMS27420100_2000C/CMS27420300_2100CA/CMS27420300_2100CA_NM1_ProviderName/@CMS27420300_2100CA_NM103_ProviderLastOrOrganizationName
    > != 0">


    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="string(...)">

    where the "..." is your XPATH expression.

    > <td>
    > <xsl:value-of
    > select="CMS27420100_2000C/CMS27420300_2100CA/CMS27420300_2100CA_NM1_ProviderName/@CMS27420300_2100CA_NM103_ProviderLastOrOrganizationName"/>
    > </td>
    > </xsl:when>
    > <xsl:eek:therwise>
    > <td bgcolor="RED"> </td>
    > </xsl:eek:therwise>
    > ---------------------------
    >
    ><xsl:choose>
    > <xsl:when
    > test="string(CMS27420100_2000C/CMS27420300_2100CA/CMS27420300_2100CA_NM1_ProviderName/@CMS27420300_2100CA_NM103_ProviderLastOrOrganizationName)
    > != 0">
    > <td>
    > <xsl:value-of
    >
    > select="CMS27420100_2000C/CMS27420300_2100CA/CMS27420300_2100CA_NM1_ProviderName/@CMS27420300_2100CA_NM103_ProviderLastOrOrganizationName"
    > />
    > </td>
    > </xsl:when>
    > <xsl:eek:therwise>
    > <td bgcolor="RED"> </td>
    > </xsl:eek:therwise>
     
    A. Bolmarcich, Jun 30, 2006
    #4
  5. Guest

    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:
    > On 2006-06-30, <> wrote:
    > > 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="CMS27420100_2000C/CMS27420300_2100CA/CMS27420300_2100CA_NM1_ProviderName/@CMS27420300_2100CA_NM103_ProviderLastOrOrganizationName
    > > != 0">

    >
    > 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="string(...)">
    >
    > where the "..." is your XPATH expression.
    >
    > > <td>
    > > <xsl:value-of
    > > select="CMS27420100_2000C/CMS27420300_2100CA/CMS27420300_2100CA_NM1_ProviderName/@CMS27420300_2100CA_NM103_ProviderLastOrOrganizationName"/>
    > > </td>
    > > </xsl:when>
    > > <xsl:eek:therwise>
    > > <td bgcolor="RED"> </td>
    > > </xsl:eek:therwise>
    > > ---------------------------
    > >
    > ><xsl:choose>
    > > <xsl:when
    > > test="string(CMS27420100_2000C/CMS27420300_2100CA/CMS27420300_2100CA_NM1_ProviderName/@CMS27420300_2100CA_NM103_ProviderLastOrOrganizationName)
    > > != 0">
    > > <td>
    > > <xsl:value-of
    > >
    > > select="CMS27420100_2000C/CMS27420300_2100CA/CMS27420300_2100CA_NM1_ProviderName/@CMS27420300_2100CA_NM103_ProviderLastOrOrganizationName"
    > > />
    > > </td>
    > > </xsl:when>
    > > <xsl:eek:therwise>
    > > <td bgcolor="RED"> </td>
    > > </xsl:eek:therwise>
     
    , Jun 30, 2006
    #5
  6. Peter Flynn Guest

    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=''"> will 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/
     
    Peter Flynn, Jul 3, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Todd
    Replies:
    2
    Views:
    512
    Sonali.NET[MVP]
    Jul 26, 2003
  2. Wolfgang
    Replies:
    1
    Views:
    551
    Patrick TJ McPhee
    Apr 9, 2004
  3. Harry Zoroc
    Replies:
    1
    Views:
    389
    Henry S. Thompson
    Jul 8, 2004
  4. ricky
    Replies:
    1
    Views:
    827
    Joris Gillis
    Oct 17, 2004
  5. Andy Fish
    Replies:
    1
    Views:
    1,513
    Andy Fish
    Dec 21, 2004
Loading...

Share This Page