Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XSLT Output - blank attributes

Reply
Thread Tools

XSLT Output - blank attributes

 
 
requeth@gmail.com
Guest
Posts: n/a
 
      06-29-2006
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

 
Reply With Quote
 
 
 
 
Joe Kesselman
Guest
Posts: n/a
 
      06-30-2006
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
 
Reply With Quote
 
 
 
 
requeth@gmail.com
Guest
Posts: n/a
 
      06-30-2006
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_ProviderLastOrOrganizati onName
!= 0">
<td>
<xsl:value-of
select="CMS27420100_2000C/CMS27420300_2100CA/CMS27420300_2100CA_NM1_ProviderName/@CMS27420300_2100CA_NM103_ProviderLastOrOrganizati onName"/>
</td>
</xsl:when>
<xsltherwise>
<td bgcolor="RED"> </td>
</xsltherwise>
---------------------------

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

select="CMS27420100_2000C/CMS27420300_2100CA/CMS27420300_2100CA_NM1_ProviderName/@CMS27420300_2100CA_NM103_ProviderLastOrOrganizati onName"
/>
</td>
</xsl:when>
<xsltherwise>
<td bgcolor="RED"> </td>
</xsltherwise>
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


 
Reply With Quote
 
A. Bolmarcich
Guest
Posts: n/a
 
      06-30-2006
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_ProviderLastOrOrganizati onName
> != 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_ProviderLastOrOrganizati onName"/>
> </td>
> </xsl:when>
> <xsltherwise>
> <td bgcolor="RED"> </td>
> </xsltherwise>
> ---------------------------
>
><xsl:choose>
> <xsl:when
> test="string(CMS27420100_2000C/CMS27420300_2100CA/CMS27420300_2100CA_NM1_ProviderName/@CMS27420300_2100CA_NM103_ProviderLastOrOrganizati onName)
> != 0">
> <td>
> <xsl:value-of
>
> select="CMS27420100_2000C/CMS27420300_2100CA/CMS27420300_2100CA_NM1_ProviderName/@CMS27420300_2100CA_NM103_ProviderLastOrOrganizati onName"
> />
> </td>
> </xsl:when>
> <xsltherwise>
> <td bgcolor="RED"> </td>
> </xsltherwise>

 
Reply With Quote
 
requeth@gmail.com
Guest
Posts: n/a
 
      06-30-2006
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_ProviderLastOrOrganizati onName
> > != 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_ProviderLastOrOrganizati onName"/>
> > </td>
> > </xsl:when>
> > <xsltherwise>
> > <td bgcolor="RED"> </td>
> > </xsltherwise>
> > ---------------------------
> >
> ><xsl:choose>
> > <xsl:when
> > test="string(CMS27420100_2000C/CMS27420300_2100CA/CMS27420300_2100CA_NM1_ProviderName/@CMS27420300_2100CA_NM103_ProviderLastOrOrganizati onName)
> > != 0">
> > <td>
> > <xsl:value-of
> >
> > select="CMS27420100_2000C/CMS27420300_2100CA/CMS27420300_2100CA_NM1_ProviderName/@CMS27420300_2100CA_NM103_ProviderLastOrOrganizati onName"
> > />
> > </td>
> > </xsl:when>
> > <xsltherwise>
> > <td bgcolor="RED"> </td>
> > </xsltherwise>


 
Reply With Quote
 
Peter Flynn
Guest
Posts: n/a
 
      07-03-2006
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/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
blank CD-R and blank DVD-R not recognized by Vista 64 Ultimate =?Utf-8?B?R3JlZyBLaXJrcGF0cmljaw==?= Windows 64bit 13 11-07-2007 12:23 PM
extra blank lines appear when rendering <textarea> from xslt Andy Fish XML 1 12-21-2004 10:52 AM
Simple (?) output of attributes with XSLT does not work Harry Zoroc XML 1 07-08-2004 10:26 AM
Undesired (maybe) attributes in root element of XSLT output Wolfgang XML 1 04-09-2004 04:18 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57